-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPascalType.Classes.pas
More file actions
695 lines (587 loc) · 20.9 KB
/
PascalType.Classes.pas
File metadata and controls
695 lines (587 loc) · 20.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
unit PascalType.Classes;
////////////////////////////////////////////////////////////////////////////////
// //
// Version: MPL 1.1 or LGPL 2.1 with linking exception //
// //
// The contents of this file are subject to the Mozilla Public License //
// Version 1.1 (the "License"); you may not use this file except in //
// compliance with the License. You may obtain a copy of the License at //
// http://www.mozilla.org/MPL/ //
// //
// Software distributed under the License is distributed on an "AS IS" //
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the //
// License for the specific language governing rights and limitations under //
// the License. //
// //
// Alternatively, the contents of this file may be used under the terms of //
// the Free Pascal modified version of the GNU Lesser General Public //
// License Version 2.1 (the "FPC modified LGPL License"), in which case the //
// provisions of this license are applicable instead of those above. //
// Please see the file LICENSE.txt for additional information concerning //
// this license. //
// //
// The code is part of the PascalType Project //
// //
// The initial developer of this code is Christian-W. Budde //
// //
// Portions created by Christian-W. Budde are Copyright (C) 2010-2021 //
// by Christian-W. Budde. All Rights Reserved. //
// //
////////////////////////////////////////////////////////////////////////////////
interface
{$I PT_Compiler.inc}
uses
Generics.Collections,
Classes, SysUtils,
Types,
PascalType.Types;
type
// A GlyphID
TGlyphID = Word;
TGlyphString = TArray<TGlyphID>;
TGlyphStrings = TArray<TGlyphString>;
const
PT_ON_CURVE = $01; // Used for both Quadratic and Cubic
PT_QUAD_CONTROL = $02; // Used for TrueType quadratic control points
PT_CUBIC_CONTROL = $04; // Used for CFF cubic control points
type
TContourPoint = record
XPos: Single;
YPos: Single;
Flags: Byte;
end;
PContourPoint = ^TContourPoint;
TPascalTypeContour = TArray<TContourPoint>;
TPascalTypePath = TArray<TPascalTypeContour>;
type
TCustomPascalTypeNamedTable = class;
TCustomPascalTypeNamedTableClass = class of TCustomPascalTypeNamedTable;
IPascalTypeFontFace = interface(IUnknown)
['{D7091B87-438D-40DA-A3C9-966953046200}']
function GetTableByTableName(const TableName: TTableName): TCustomPascalTypeNamedTable;
function GetTableByTableType(const TableType: TTableType): TCustomPascalTypeNamedTable;
function GetTableByTableClass(TableClass: TCustomPascalTypeNamedTableClass): TCustomPascalTypeNamedTable;
function GetGlyphName(GlyphID: TGlyphID): string;
function GetAdvanceWidth(GlyphIndex: Word): Word;
function GetAdvanceHeight(GlyphIndex: Word): Word;
function GetVerticalOrigin(GlyphIndex: Word): TPoint;
{$if defined(PhantomPoints)}
function GetGlyphPointCount(GlyphID: TGlyphID): Integer;
{$ifend}
// Variations
function GetHasVariations: boolean;
property HasVariations: boolean read GetHasVariations;
function GetVariationsActive: boolean;
property VariationsActive: boolean read GetVariationsActive;
function GetVariationItemDelta(OuterIndex, InnerIndex: Word): Single;
function GetVariationMetricDelta(const Tag: TTableType): Single;
function GetVariationNormalizedCoordinates: TArray<TFixedPoint>;
property VariationNormalizedCoordinates: TArray<TFixedPoint> read GetVariationNormalizedCoordinates;
end;
TCustomPascalTypeTable = class abstract(TInterfacedPersistent)
private
FParent: TCustomPascalTypeTable;
protected
procedure Changed; virtual;
function GetFontFace: IPascalTypeFontFace; virtual;
public
constructor Create(AParent: TCustomPascalTypeTable = nil); virtual;
procedure Assign(Source: TPersistent); override;
// Most tables don't need to know the size of the data being loaded, but
// a few do (e.g. 'cvt') so we have to pass the size along if it's known.
procedure LoadFromStream(Stream: TStream; Size: Cardinal = 0); virtual;
procedure SaveToStream(Stream: TStream); virtual;
property Parent: TCustomPascalTypeTable read FParent;
property FontFace: IPascalTypeFontFace read GetFontFace;
end;
TPascalTypeTableClass = class of TCustomPascalTypeTable;
TCustomPascalTypeNamedTable = class(TCustomPascalTypeTable)
protected
function GetInternalTableType: TTableType; virtual;
public
class function GetTableType: TTableType; virtual; abstract;
procedure WriteTableTypeToStream(Stream: TStream); virtual;
property TableType: TTableType read GetInternalTableType;
end;
TPascalTypeTableList<T: TCustomPascalTypeTable> = class(TObjectList<T>)
public
function Add: T; overload; virtual;
function Add(ATableClass: TPascalTypeTableClass): T; overload;
procedure Assign(Source: TPascalTypeTableList<T>);
end;
TPascalTypeTableInterfaceList<T: TCustomPascalTypeTable> = class(TPascalTypeTableList<T>)
private
FParent: TCustomPascalTypeTable;
protected
property Parent: TCustomPascalTypeTable read FParent;
public
constructor Create(AParent: TCustomPascalTypeTable);
function Add: T; overload; override;
function Add(ATableClass: TPascalTypeTableClass): T; overload;
procedure Assign(Source: TPascalTypeTableList<T>);
end;
type
EndianValue = class
protected
class procedure Process(const ASource; var ADest; ASize, AElementSize: integer); virtual;
public
class procedure Read<T>(AStream: TStream; var Buffer: T); overload;
class procedure Read<T>(AStream: TStream; var Buffer; Count: integer); overload;
class procedure Write<T>(AStream: TStream; const Buffer: T); overload;
class procedure Write<T>(AStream: TStream; const Buffer; Count: integer); overload;
// String
class function ReadAnsiString(AStream: TStream): AnsiString; overload;
class procedure WriteAnsiString(AStream: TStream; const s: AnsiString); overload;
// 8 bit
class function ReadByte(AStream: TStream): Byte; overload;
class procedure ReadByte(AStream: TStream; var Buffer; Count: integer = 1); overload;
class function ReadShortInt(AStream: TStream): ShortInt; overload;
class procedure ReadShortInt(AStream: TStream; var Buffer; Count: integer = 1); overload;
class procedure WriteByte(AStream: TStream; AValue: Byte); overload;
class procedure WriteByte(AStream: TStream; var Buffer; Count: integer); overload;
class procedure WriteShortInt(AStream: TStream; AValue: ShortInt); overload;
class procedure WriteShortInt(AStream: TStream; var Buffer; Count: integer); overload;
// 16 bit
class function ReadWord(AStream: TStream): Word; overload;
class procedure ReadWord(AStream: TStream; var Buffer; Count: integer = 1); overload;
class function ReadSmallInt(AStream: TStream): SmallInt; overload;
class procedure ReadSmallInt(AStream: TStream; var Buffer; Count: integer = 1); overload;
class procedure WriteWord(AStream: TStream; AValue: Word); overload;
class procedure WriteWord(AStream: TStream; var Buffer; Count: integer); overload;
class procedure WriteSmallInt(AStream: TStream; AValue: SmallInt); overload;
class procedure WriteSmallInt(AStream: TStream; var Buffer; Count: integer); overload;
// 24 bit
class function ReadUInt24(AStream: TStream): Cardinal; overload; virtual;
class procedure ReadUInt24(AStream: TStream; var Buffer; Count: integer = 1); overload; virtual;
class procedure WriteUInt24(AStream: TStream; AValue: Cardinal); overload; virtual;
class procedure WriteUInt24(AStream: TStream; const Buffer; Count: integer = 1); overload; virtual;
// 32 bit
class function ReadCardinal(AStream: TStream): Cardinal; overload;
class procedure ReadCardinal(AStream: TStream; var Buffer; Count: integer = 1); overload;
class function ReadInteger(AStream: TStream): Integer; overload;
class procedure ReadInteger(AStream: TStream; var Buffer; Count: integer = 1); overload;
class procedure WriteCardinal(AStream: TStream; AValue: Cardinal); overload;
class procedure WriteCardinal(AStream: TStream; var Buffer; Count: integer); overload;
class procedure WriteInteger(AStream: TStream; AValue: Integer); overload;
class procedure WriteInteger(AStream: TStream; var Buffer; Count: integer); overload;
// 64 bit
class function ReadUInt64(AStream: TStream): UInt64; overload;
class procedure ReadUInt64(AStream: TStream; var Buffer; Count: integer = 1); overload;
class function ReadInt64(AStream: TStream): Int64; overload;
class procedure ReadInt64(AStream: TStream; var Buffer; Count: integer = 1); overload;
class procedure WriteUInt64(AStream: TStream; AValue: UInt64); overload;
class procedure WriteUInt64(AStream: TStream; var Buffer; Count: integer); overload;
class procedure WriteInt64(AStream: TStream; AValue: Int64); overload;
class procedure WriteInt64(AStream: TStream; var Buffer; Count: Int64); overload;
class procedure Copy<T>(const ASource; var ADest: T; ASize: integer); overload;
class procedure Copy(ASource, ADest: PWord; ACount: integer); overload;
end;
BigEndianValue = class(EndianValue)
protected
class procedure Process(const ASource; var ADest; ASize, AElementSize: integer); override;
public
// 24 bit
class function ReadUInt24(AStream: TStream): Cardinal; overload; override;
class procedure ReadUInt24(AStream: TStream; var Buffer; Count: integer = 1); overload; override;
class procedure WriteUInt24(AStream: TStream; AValue: Cardinal); overload; override;
class procedure WriteUInt24(AStream: TStream; const Buffer; Count: integer = 1); overload; override;
end;
implementation
uses
PascalType.Math,
PascalType.ResourceStrings;
{ TPascalTypeTableList<T> }
function TPascalTypeTableList<T>.Add: T;
begin
Result := T.Create;
Add(Result);
end;
function TPascalTypeTableList<T>.Add(ATableClass: TPascalTypeTableClass): T;
begin
Result := T(ATableClass.Create);
Add(Result);
end;
procedure TPascalTypeTableList<T>.Assign(Source: TPascalTypeTableList<T>);
var
SourceItem: T;
DestItem: T;
begin
Clear;
for SourceItem in Source do
begin
DestItem := T(TPascalTypeTableClass(SourceItem.ClassType).Create);
Add(DestItem);
DestItem.Assign(SourceItem);
end;
end;
{ TPascalTypeTableInterfaceList<T> }
function TPascalTypeTableInterfaceList<T>.Add: T;
begin
Result := T(TPascalTypeTableClass(T).Create(FParent));
Add(Result);
end;
function TPascalTypeTableInterfaceList<T>.Add(ATableClass: TPascalTypeTableClass): T;
begin
Result := T(ATableClass.Create(FParent));
Add(Result);
end;
procedure TPascalTypeTableInterfaceList<T>.Assign(Source: TPascalTypeTableList<T>);
var
SourceItem: T;
DestItem: T;
begin
Clear;
for SourceItem in Source do
begin
DestItem := Add(TPascalTypeTableClass(SourceItem.ClassType));
DestItem.Assign(SourceItem);
end;
end;
constructor TPascalTypeTableInterfaceList<T>.Create(AParent: TCustomPascalTypeTable);
begin
inherited Create;
FParent := AParent;
end;
{ TCustomPascalTypeTable }
constructor TCustomPascalTypeTable.Create(AParent: TCustomPascalTypeTable);
begin
inherited Create;
FParent := AParent;
end;
(*
constructor TCustomPascalTypeTable.CreateHidden;
begin
end;
*)
function TCustomPascalTypeTable.GetFontFace: IPascalTypeFontFace;
begin
if (Parent <> nil) then
Result := Parent.FontFace
else
Result := nil;
end;
procedure TCustomPascalTypeTable.LoadFromStream(Stream: TStream; Size: Cardinal);
begin
end;
procedure TCustomPascalTypeTable.SaveToStream(Stream: TStream);
begin
end;
procedure TCustomPascalTypeTable.Assign(Source: TPersistent);
begin
if (Source is TCustomPascalTypeTable) then
begin
// Backstop
end else
inherited;
end;
procedure TCustomPascalTypeTable.Changed;
begin
// nothing here yet
end;
{ TCustomPascalTypeNamedTable }
function TCustomPascalTypeNamedTable.GetInternalTableType: TTableType;
begin
Result := GetTableType;
end;
procedure TCustomPascalTypeNamedTable.WriteTableTypeToStream(Stream: TStream);
var
TableName: TTableType;
begin
// store chunk name to memory stream
TableName := TableType;
Stream.Write(TableName, 4);
end;
{ EndianValue }
class procedure EndianValue.Copy(ASource, ADest: PWord; ACount: integer);
begin
Copy<Word>(ASource^, ADest^, ACount * SizeOf(Word));
end;
class procedure EndianValue.Copy<T>(const ASource; var ADest: T; ASize: integer);
begin
Process(ADest, ASize, ASize, SizeOf(T));
end;
class procedure EndianValue.Process(const ASource; var ADest; ASize, AElementSize: integer);
begin
Move(ASource, ADest, ASize);
end;
class procedure EndianValue.Write<T>(AStream: TStream; const Buffer: T);
begin
Write<T>(AStream, Buffer, 1);
end;
class procedure EndianValue.Write<T>(AStream: TStream; const Buffer; Count: integer);
var
p: ^T;
Value: T;
begin
p := @Buffer;
while (Count > 0) do
begin
Process(p^, Value, SizeOf(T), SizeOf(T));
AStream.Write(Value, SizeOf(T));
Inc(p);
Dec(Count);
end;
end;
class procedure EndianValue.WriteAnsiString(AStream: TStream; const s: AnsiString);
begin
WriteByte(AStream, Length(s));
if (s <> '') then
AStream.Write(s[1], Length(s));
end;
class procedure EndianValue.WriteByte(AStream: TStream; AValue: Byte);
begin
Write(AStream, AValue);
end;
class procedure EndianValue.WriteByte(AStream: TStream; var Buffer; Count: integer);
begin
Write<Byte>(AStream, Buffer, Count);
end;
class procedure EndianValue.WriteShortInt(AStream: TStream; AValue: ShortInt);
begin
Write(AStream, AValue);
end;
class procedure EndianValue.WriteShortInt(AStream: TStream; var Buffer; Count: integer);
begin
Write<ShortInt>(AStream, Buffer, Count);
end;
class procedure EndianValue.WriteSmallInt(AStream: TStream; AValue: SmallInt);
begin
Write(AStream, AValue);
end;
class procedure EndianValue.WriteSmallInt(AStream: TStream; var Buffer; Count: integer);
begin
Write<SmallInt>(AStream, Buffer, Count);
end;
class procedure EndianValue.WriteWord(AStream: TStream; AValue: Word);
begin
Write(AStream, AValue);
end;
class procedure EndianValue.WriteWord(AStream: TStream; var Buffer; Count: integer);
begin
Write<Word>(AStream, Buffer, Count);
end;
class procedure EndianValue.WriteCardinal(AStream: TStream; AValue: Cardinal);
begin
Write(AStream, AValue);
end;
class procedure EndianValue.WriteCardinal(AStream: TStream; var Buffer; Count: integer);
begin
Write<Cardinal>(AStream, Buffer, Count);
end;
class procedure EndianValue.WriteInteger(AStream: TStream; AValue: Integer);
begin
Write(AStream, AValue);
end;
class procedure EndianValue.WriteInteger(AStream: TStream; var Buffer; Count: integer);
begin
Write<Integer>(AStream, Buffer, Count);
end;
class procedure EndianValue.WriteUInt64(AStream: TStream; AValue: UInt64);
begin
Write(AStream, AValue);
end;
class procedure EndianValue.WriteUInt64(AStream: TStream; var Buffer; Count: integer);
begin
Write<UInt64>(AStream, Buffer, Count);
end;
class procedure EndianValue.WriteInt64(AStream: TStream; AValue: Int64);
begin
Write(AStream, AValue);
end;
class procedure EndianValue.WriteInt64(AStream: TStream; var Buffer; Count: Int64);
begin
Write<Int64>(AStream, Buffer, Count);
end;
class procedure EndianValue.Read<T>(AStream: TStream; var Buffer; Count: integer);
var
BufferSize: Int64;
ReadSize: Int64;
begin
BufferSize := SizeOf(T) * Count;
ReadSize := AStream.Read(Buffer, BufferSize);
{$IFDEF ValidateEveryReadOperation}
if ReadSize <> BufferSize then
raise EPascalTypeStremReadError.Create(RCStrStreamReadError);
{$ENDIF}
Process(Buffer, Buffer, ReadSize, SizeOf(T));
end;
class function EndianValue.ReadAnsiString(AStream: TStream): AnsiString;
var
Size: Byte;
begin
Size := ReadByte(AStream);
SetLength(Result, Size);
if (Size > 0) then
AStream.Read(Result[1], Size);
end;
class procedure EndianValue.Read<T>(AStream: TStream; var Buffer: T);
begin
Read<T>(AStream, Buffer, 1);
end;
class procedure EndianValue.ReadByte(AStream: TStream; var Buffer; Count: integer);
begin
Read<Byte>(AStream, Buffer, Count);
end;
class function EndianValue.ReadByte(AStream: TStream): Byte;
begin
Read(AStream, Result);
end;
type
UInt24 = array[0..2] of Byte;
PUInt24 = ^UInt24;
class procedure EndianValue.ReadUInt24(AStream: TStream; var Buffer; Count: integer);
var
p: PUInt24;
begin
p := @Buffer;
while (Count > 0) do
begin
AStream.Read(p^, SizeOf(UInt24));
Inc(p);
Dec(Count);
end;
end;
class procedure EndianValue.WriteUInt24(AStream: TStream; AValue: Cardinal);
begin
AStream.Write(AValue, 3);
end;
class procedure EndianValue.WriteUInt24(AStream: TStream; const Buffer; Count: integer);
begin
AStream.Write(Buffer, 3 * Count);
end;
class function EndianValue.ReadUInt24(AStream: TStream): Cardinal;
var
Value: UInt24;
begin
ReadUInt24(AStream, Value);
Result := Value[0] or (Value[1] shl 8) or (Value[2] shl 16);
end;
class procedure BigEndianValue.WriteUInt24(AStream: TStream; AValue: Cardinal);
var
Temp: UInt24;
begin
Temp[0] := (AValue shr 16) and $FF;
Temp[1] := (AValue shr 8) and $FF;
Temp[2] := AValue and $FF;
AStream.Write(Temp, 3);
end;
class procedure BigEndianValue.WriteUInt24(AStream: TStream; const Buffer; Count: integer);
var
pSource: PUInt24;
Temp: UInt24;
b: Byte;
begin
pSource := @Buffer;
while (Count > 0) do
begin
Temp := pSource^;
b := Temp[2];
Temp[2] := Temp[0];
Temp[0] := b;
AStream.Write(Temp, 3);
Inc(pSource);
Dec(Count);
end;
end;
class procedure EndianValue.ReadCardinal(AStream: TStream; var Buffer; Count: integer);
begin
Read<Cardinal>(AStream, Buffer, Count);
end;
class function EndianValue.ReadCardinal(AStream: TStream): Cardinal;
begin
Read(AStream, Result);
end;
class procedure EndianValue.ReadInt64(AStream: TStream; var Buffer; Count: integer);
begin
Read<Int64>(AStream, Buffer, Count);
end;
class function EndianValue.ReadInt64(AStream: TStream): Int64;
begin
Read(AStream, Result);
end;
class procedure EndianValue.ReadInteger(AStream: TStream; var Buffer; Count: integer);
begin
Read<Integer>(AStream, Buffer, Count);
end;
class function EndianValue.ReadInteger(AStream: TStream): Integer;
begin
Read(AStream, Result);
end;
class procedure EndianValue.ReadShortInt(AStream: TStream; var Buffer; Count: integer);
begin
Read<ShortInt>(AStream, Buffer, Count);
end;
class function EndianValue.ReadShortInt(AStream: TStream): ShortInt;
begin
Read(AStream, Result);
end;
class procedure EndianValue.ReadSmallInt(AStream: TStream; var Buffer; Count: integer);
begin
Read<SmallInt>(AStream, Buffer, Count);
end;
class function EndianValue.ReadSmallInt(AStream: TStream): SmallInt;
begin
Read(AStream, Result);
end;
class procedure EndianValue.ReadUInt64(AStream: TStream; var Buffer; Count: integer);
begin
Read<UInt64>(AStream, Buffer, Count);
end;
class function EndianValue.ReadUInt64(AStream: TStream): UInt64;
begin
Read(AStream, Result);
end;
class procedure EndianValue.ReadWord(AStream: TStream; var Buffer; Count: integer);
begin
Read<Word>(AStream, Buffer, Count);
end;
class function EndianValue.ReadWord(AStream: TStream): Word;
begin
Read(AStream, Result);
end;
{ BigEndianValue }
class procedure BigEndianValue.Process(const ASource; var ADest; ASize, AElementSize: integer);
var
pSource, pDest: PByte;
begin
pSource := @ASource;
pDest := @ADest;
while (ASize >= AElementSize) do
begin
case AElementSize of
1: ;
2: PWord(pDest)^ := Swap16(PWord(pSource)^);
4: PCardinal(pDest)^ := Swap32(PCardinal(pSource)^);
8: PInt64(pDest)^ := Swap64(PInt64(pSource)^);
else
Assert(False);
end;
Inc(pSource, AElementSize);
Inc(pDest, AElementSize);
Dec(ASize, AElementSize);
end;
end;
class procedure BigEndianValue.ReadUInt24(AStream: TStream; var Buffer; Count: integer);
var
p: PUInt24;
Temp: Byte;
begin
p := @Buffer;
while (Count > 0) do
begin
AStream.Read(p^, SizeOf(UInt24));
Temp := p^[2];
p^[2] := p^[0];
p^[0] := Temp;
Inc(p);
Dec(Count);
end;
end;
class function BigEndianValue.ReadUInt24(AStream: TStream): Cardinal;
var
Value: UInt24;
begin
ReadUInt24(AStream, Value);
Result := Value[0] or (Value[1] shl 8) or (Value[2] shl 16);
end;
end.