|
@@ -31,26 +31,6 @@ type
|
|
// Tables recognized in this unit.
|
|
// Tables recognized in this unit.
|
|
TTTFTableType = (ttUnknown,ttHead,tthhea,ttmaxp,tthmtx,ttcmap,ttname,ttOS2,ttpost);
|
|
TTTFTableType = (ttUnknown,ttHead,tthhea,ttmaxp,tthmtx,ttcmap,ttname,ttOS2,ttpost);
|
|
|
|
|
|
- TPDFFontDefinition = Record
|
|
|
|
- FontType : String;
|
|
|
|
- FontName : String;
|
|
|
|
- Ascender : Integer;
|
|
|
|
- Descender : Integer;
|
|
|
|
- CapHeight : Integer;
|
|
|
|
- Flags : Integer;
|
|
|
|
- BBox : Array[0..3] of Integer;
|
|
|
|
- ItalicAngle : Integer;
|
|
|
|
- StemV : Integer;
|
|
|
|
- MissingWidth : integer;
|
|
|
|
- FontUp : Integer;
|
|
|
|
- FontUt : Integer;
|
|
|
|
- Encoding : String;
|
|
|
|
- FontFile : String;
|
|
|
|
- Diffs : String;
|
|
|
|
- CharWidths : String;
|
|
|
|
- OriginalSize : integer;
|
|
|
|
- end;
|
|
|
|
-
|
|
|
|
TSmallintArray = Packed Array of Int16;
|
|
TSmallintArray = Packed Array of Int16;
|
|
TWordArray = Packed Array of UInt16;
|
|
TWordArray = Packed Array of UInt16;
|
|
|
|
|
|
@@ -253,10 +233,11 @@ Type
|
|
FWidths: TLongHorMetrics; // hmtx data
|
|
FWidths: TLongHorMetrics; // hmtx data
|
|
// Needed to create PDF font def.
|
|
// Needed to create PDF font def.
|
|
FOriginalSize : Cardinal;
|
|
FOriginalSize : Cardinal;
|
|
- MissingWidth: Integer;
|
|
|
|
|
|
+ FMissingWidth: Integer;
|
|
FNameEntries: TNameEntries;
|
|
FNameEntries: TNameEntries;
|
|
{ This only applies to TFixedVersionRec values. }
|
|
{ This only applies to TFixedVersionRec values. }
|
|
function FixMinorVersion(const AMinor: word): word;
|
|
function FixMinorVersion(const AMinor: word): word;
|
|
|
|
+ function GetMissingWidth: integer;
|
|
Protected
|
|
Protected
|
|
// Stream reading functions.
|
|
// Stream reading functions.
|
|
Function IsNativeData : Boolean; virtual;
|
|
Function IsNativeData : Boolean; virtual;
|
|
@@ -273,23 +254,10 @@ Type
|
|
procedure ParseOS2(AStream : TStream); virtual;
|
|
procedure ParseOS2(AStream : TStream); virtual;
|
|
procedure ParsePost(AStream : TStream); virtual;
|
|
procedure ParsePost(AStream : TStream); virtual;
|
|
// Make differences for postscript fonts
|
|
// Make differences for postscript fonts
|
|
- procedure PrepareEncoding(Const AEnCoding : String);
|
|
|
|
|
|
+ procedure PrepareEncoding(Const AEncoding : String);
|
|
function MakeDifferences: String; virtual;
|
|
function MakeDifferences: String; virtual;
|
|
// Utility function to convert FShort to natural units
|
|
// Utility function to convert FShort to natural units
|
|
Function ToNatural(AUnit: Smallint) : Smallint;
|
|
Function ToNatural(AUnit: Smallint) : Smallint;
|
|
- // Some utility functions to create the PDF font definition
|
|
|
|
- Procedure MakePDFFontDefinitionFile(Const FontFile,Section,AEncoding: string); virtual;
|
|
|
|
- Function Flags : Integer;
|
|
|
|
- Function Bold: Boolean;
|
|
|
|
- Function StemV: SmallInt;
|
|
|
|
- Function Embeddable : Boolean;
|
|
|
|
- Function Ascender: SmallInt;
|
|
|
|
- Function Descender: SmallInt;
|
|
|
|
- { Also know as the linegap. "Leading" is the gap between two lines. }
|
|
|
|
- Function Leading: SmallInt;
|
|
|
|
- Function CapHeight: SmallInt;
|
|
|
|
- { Returns the glyph advance width, based on the AIndex (glyph index) value. The result is in font units. }
|
|
|
|
- function GetAdvanceWidth(AIndex: word): word;
|
|
|
|
public
|
|
public
|
|
Chars: TWordArray;
|
|
Chars: TWordArray;
|
|
CharWidth: array[0..255] of SmallInt;
|
|
CharWidth: array[0..255] of SmallInt;
|
|
@@ -304,17 +272,32 @@ Type
|
|
// Load a TTF file from file or stream.
|
|
// Load a TTF file from file or stream.
|
|
Procedure LoadFromFile(const AFileName : String);
|
|
Procedure LoadFromFile(const AFileName : String);
|
|
Procedure LoadFromStream(AStream: TStream); virtual;
|
|
Procedure LoadFromStream(AStream: TStream); virtual;
|
|
- // Checks if Embedded is allowed, and also prepares CharWidths array
|
|
|
|
|
|
+ // Checks if Embedded is allowed, and also prepares CharWidths array. NOTE: this is possibly not needed any more.
|
|
procedure PrepareFontDefinition(const Encoding:string; Embed: Boolean);
|
|
procedure PrepareFontDefinition(const Encoding:string; Embed: Boolean);
|
|
- // Fill record with PDF Font definition data.
|
|
|
|
- Procedure FillPDFFontDefinition(Out ADef: TPDFFontDefinition; Const AFontFile,AEncoding : String);
|
|
|
|
- // Write Font Definition data to a file named FontFile.
|
|
|
|
- procedure MakePDFFontDef(const FontFile: string; const Encoding: string; Embed: Boolean);
|
|
|
|
|
|
+
|
|
// The following are only valid after the file was succesfully read.
|
|
// The following are only valid after the file was succesfully read.
|
|
- // Font file header info.
|
|
|
|
|
|
+
|
|
|
|
+ Function Flags : Integer;
|
|
|
|
+ Function Bold: Boolean;
|
|
|
|
+ Function StemV: SmallInt;
|
|
|
|
+ Function Embeddable : Boolean;
|
|
|
|
+ Function Ascender: SmallInt;
|
|
|
|
+ Function Descender: SmallInt;
|
|
|
|
+ { Also know as the linegap. "Leading" is the gap between two lines. }
|
|
|
|
+ Function Leading: SmallInt;
|
|
|
|
+ Function CapHeight: SmallInt;
|
|
|
|
+ { Returns the glyph advance width, based on the AIndex (glyph index) value. The result is in font units. }
|
|
|
|
+ function GetAdvanceWidth(AIndex: word): word;
|
|
|
|
+ function ItalicAngle: LongWord;
|
|
|
|
+ { max glyph bounding box values - as space separated values }
|
|
|
|
+ function BBox: string;
|
|
|
|
+ property MissingWidth: Integer read GetMissingWidth;
|
|
|
|
+ { original font file size }
|
|
|
|
+ property OriginalSize: Cardinal read FOriginalSize;
|
|
|
|
+ property Filename: string read FFilename;
|
|
Property Directory : TTableDirectory Read FTableDir;
|
|
Property Directory : TTableDirectory Read FTableDir;
|
|
Property Tables : TTableDirectoryEntries Read FTables;
|
|
Property Tables : TTableDirectoryEntries Read FTables;
|
|
- // The various tables as present in the font file.
|
|
|
|
|
|
+
|
|
Property Head : THead Read FHead;
|
|
Property Head : THead Read FHead;
|
|
Property HHead : THHead Read FHHead;
|
|
Property HHead : THHead Read FHHead;
|
|
property CmapH : TCMapHeader Read FCmapH;
|
|
property CmapH : TCMapHeader Read FCmapH;
|
|
@@ -338,12 +321,9 @@ type
|
|
|
|
|
|
// Convert string to known table type
|
|
// Convert string to known table type
|
|
Function GetTableType(Const AName : String) : TTTFTableType;
|
|
Function GetTableType(Const AName : String) : TTTFTableType;
|
|
-// Utility functions for text encoding conversions
|
|
|
|
-function ConvertUTF8ToUTF16(Dest: PWideChar; DestWideCharCount: SizeUInt; Src: PChar; SrcCharCount: SizeUInt;
|
|
|
|
- Options: TConvertOptions; out ActualWideCharCount: SizeUInt): TConvertResult;
|
|
|
|
-function UTF8ToUTF16(const P: PChar; ByteCnt: SizeUInt): UnicodeString;
|
|
|
|
-function UTF8ToUTF16(const S: AnsiString): UnicodeString;
|
|
|
|
function StrToUTF16Hex(const AValue: UnicodeString; AIncludeBOM: boolean = True): AnsiString;
|
|
function StrToUTF16Hex(const AValue: UnicodeString; AIncludeBOM: boolean = True): AnsiString;
|
|
|
|
+{ To overcome the annoying compiler hint: "Local variable does not seem to be initialized" }
|
|
|
|
+procedure FillMem(Dest: pointer; Size: longint; Data: Byte );
|
|
|
|
|
|
|
|
|
|
Const
|
|
Const
|
|
@@ -373,8 +353,6 @@ Const
|
|
|
|
|
|
implementation
|
|
implementation
|
|
|
|
|
|
-uses
|
|
|
|
- inifiles;
|
|
|
|
|
|
|
|
resourcestring
|
|
resourcestring
|
|
rsFontEmbeddingNotAllowed = 'Font licence does not allow embedding';
|
|
rsFontEmbeddingNotAllowed = 'Font licence does not allow embedding';
|
|
@@ -386,222 +364,6 @@ begin
|
|
Result:=Pred(Result);
|
|
Result:=Pred(Result);
|
|
end;
|
|
end;
|
|
|
|
|
|
-{------------------------------------------------------------------------------
|
|
|
|
- Name: ConvertUTF8ToUTF16
|
|
|
|
- Params: Dest - Pointer to destination string
|
|
|
|
- DestWideCharCount - Wide char count allocated in destination string
|
|
|
|
- Src - Pointer to source string
|
|
|
|
- SrcCharCount - Char count allocated in source string
|
|
|
|
- Options - Conversion options, if none is set, both
|
|
|
|
- invalid and unfinished source chars are skipped
|
|
|
|
-
|
|
|
|
- toInvalidCharError - Stop on invalid source char and report
|
|
|
|
- error
|
|
|
|
- toInvalidCharToSymbol - Replace invalid source chars with '?'
|
|
|
|
- toUnfinishedCharError - Stop on unfinished source char and
|
|
|
|
- report error
|
|
|
|
- toUnfinishedCharToSymbol - Replace unfinished source char with '?'
|
|
|
|
-
|
|
|
|
- ActualWideCharCount - Actual wide char count converted from source
|
|
|
|
- string to destination string
|
|
|
|
- Returns:
|
|
|
|
- trNoError - The string was successfully converted without
|
|
|
|
- any error
|
|
|
|
- trNullSrc - Pointer to source string is nil
|
|
|
|
- trNullDest - Pointer to destination string is nil
|
|
|
|
- trDestExhausted - Destination buffer size is not big enough to hold
|
|
|
|
- converted string
|
|
|
|
- trInvalidChar - Invalid source char has occured
|
|
|
|
- trUnfinishedChar - Unfinished source char has occured
|
|
|
|
-
|
|
|
|
- Converts the specified UTF-8 encoded string to UTF-16 encoded (system endian)
|
|
|
|
- ------------------------------------------------------------------------------}
|
|
|
|
-function ConvertUTF8ToUTF16(Dest: PWideChar; DestWideCharCount: SizeUInt;
|
|
|
|
- Src: PChar; SrcCharCount: SizeUInt; Options: TConvertOptions;
|
|
|
|
- out ActualWideCharCount: SizeUInt): TConvertResult;
|
|
|
|
-var
|
|
|
|
- DestI, SrcI: SizeUInt;
|
|
|
|
- B1, B2, B3, B4: Byte;
|
|
|
|
- W: Word;
|
|
|
|
- C: Cardinal;
|
|
|
|
-
|
|
|
|
- function UnfinishedCharError: Boolean;
|
|
|
|
- begin
|
|
|
|
- if toUnfinishedCharToSymbol in Options then
|
|
|
|
- begin
|
|
|
|
- Dest[DestI] := System.WideChar('?');
|
|
|
|
- Inc(DestI);
|
|
|
|
- Result := False;
|
|
|
|
- end
|
|
|
|
- else
|
|
|
|
- if toUnfinishedCharError in Options then
|
|
|
|
- begin
|
|
|
|
- ConvertUTF8ToUTF16 := trUnfinishedChar;
|
|
|
|
- Result := True;
|
|
|
|
- end
|
|
|
|
- else Result := False;
|
|
|
|
- end;
|
|
|
|
-
|
|
|
|
- function InvalidCharError(Count: SizeUInt): Boolean; inline;
|
|
|
|
- begin
|
|
|
|
- if not (toInvalidCharError in Options) then
|
|
|
|
- begin
|
|
|
|
- if toInvalidCharToSymbol in Options then
|
|
|
|
- begin
|
|
|
|
- Dest[DestI] := System.WideChar('?');
|
|
|
|
- Inc(DestI);
|
|
|
|
- end;
|
|
|
|
-
|
|
|
|
- Dec(SrcI, Count);
|
|
|
|
-
|
|
|
|
- // skip trailing UTF-8 char bytes
|
|
|
|
- while (Count > 0) do
|
|
|
|
- begin
|
|
|
|
- if (Byte(Src[SrcI]) and %11000000) <> %10000000 then Break;
|
|
|
|
- Inc(SrcI);
|
|
|
|
- Dec(Count);
|
|
|
|
- end;
|
|
|
|
-
|
|
|
|
- Result := False;
|
|
|
|
- end
|
|
|
|
- else
|
|
|
|
- if toInvalidCharError in Options then
|
|
|
|
- begin
|
|
|
|
- ConvertUTF8ToUTF16 := trUnfinishedChar;
|
|
|
|
- Result := True;
|
|
|
|
- end;
|
|
|
|
- end;
|
|
|
|
-
|
|
|
|
-begin
|
|
|
|
- ActualWideCharCount := 0;
|
|
|
|
-
|
|
|
|
- if not Assigned(Src) then
|
|
|
|
- begin
|
|
|
|
- Result := trNullSrc;
|
|
|
|
- Exit;
|
|
|
|
- end;
|
|
|
|
-
|
|
|
|
- if not Assigned(Dest) then
|
|
|
|
- begin
|
|
|
|
- Result := trNullDest;
|
|
|
|
- Exit;
|
|
|
|
- end;
|
|
|
|
- SrcI := 0;
|
|
|
|
- DestI := 0;
|
|
|
|
-
|
|
|
|
- while (DestI < DestWideCharCount) and (SrcI < SrcCharCount) do
|
|
|
|
- begin
|
|
|
|
- B1 := Byte(Src[SrcI]);
|
|
|
|
- Inc(SrcI);
|
|
|
|
-
|
|
|
|
- if B1 < 128 then // single byte UTF-8 char
|
|
|
|
- begin
|
|
|
|
- Dest[DestI] := System.WideChar(B1);
|
|
|
|
- Inc(DestI);
|
|
|
|
- end
|
|
|
|
- else
|
|
|
|
- begin
|
|
|
|
- if SrcI >= SrcCharCount then
|
|
|
|
- if UnfinishedCharError then Exit(trInvalidChar)
|
|
|
|
- else Break;
|
|
|
|
-
|
|
|
|
- B2 := Byte(Src[SrcI]);
|
|
|
|
- Inc(SrcI);
|
|
|
|
-
|
|
|
|
- if (B1 and %11100000) = %11000000 then // double byte UTF-8 char
|
|
|
|
- begin
|
|
|
|
- if (B2 and %11000000) = %10000000 then
|
|
|
|
- begin
|
|
|
|
- Dest[DestI] := System.WideChar(((B1 and %00011111) shl 6) or (B2 and %00111111));
|
|
|
|
- Inc(DestI);
|
|
|
|
- end
|
|
|
|
- else // invalid character, assume single byte UTF-8 char
|
|
|
|
- if InvalidCharError(1) then Exit(trInvalidChar);
|
|
|
|
- end
|
|
|
|
- else
|
|
|
|
- begin
|
|
|
|
- if SrcI >= SrcCharCount then
|
|
|
|
- if UnfinishedCharError then Exit(trInvalidChar)
|
|
|
|
- else Break;
|
|
|
|
-
|
|
|
|
- B3 := Byte(Src[SrcI]);
|
|
|
|
- Inc(SrcI);
|
|
|
|
-
|
|
|
|
- if (B1 and %11110000) = %11100000 then // triple byte UTF-8 char
|
|
|
|
- begin
|
|
|
|
- if ((B2 and %11000000) = %10000000) and ((B3 and %11000000) = %10000000) then
|
|
|
|
- begin
|
|
|
|
- W := ((B1 and %00011111) shl 12) or ((B2 and %00111111) shl 6) or (B3 and %00111111);
|
|
|
|
- if (W < $D800) or (W > $DFFF) then // to single wide char UTF-16 char
|
|
|
|
- begin
|
|
|
|
- Dest[DestI] := System.WideChar(W);
|
|
|
|
- Inc(DestI);
|
|
|
|
- end
|
|
|
|
- else // invalid UTF-16 character, assume double byte UTF-8 char
|
|
|
|
- if InvalidCharError(2) then Exit(trInvalidChar);
|
|
|
|
- end
|
|
|
|
- else // invalid character, assume double byte UTF-8 char
|
|
|
|
- if InvalidCharError(2) then Exit(trInvalidChar);
|
|
|
|
- end
|
|
|
|
- else
|
|
|
|
- begin
|
|
|
|
- if SrcI >= SrcCharCount then
|
|
|
|
- if UnfinishedCharError then Exit(trInvalidChar)
|
|
|
|
- else Break;
|
|
|
|
-
|
|
|
|
- B4 := Byte(Src[SrcI]);
|
|
|
|
- Inc(SrcI);
|
|
|
|
-
|
|
|
|
- if ((B1 and %11111000) = %11110000) and ((B2 and %11000000) = %10000000)
|
|
|
|
- and ((B3 and %11000000) = %10000000) and ((B4 and %11000000) = %10000000) then
|
|
|
|
- begin // 4 byte UTF-8 char
|
|
|
|
- C := ((B1 and %00011111) shl 18) or ((B2 and %00111111) shl 12)
|
|
|
|
- or ((B3 and %00111111) shl 6) or (B4 and %00111111);
|
|
|
|
- // to double wide char UTF-16 char
|
|
|
|
- Dest[DestI] := System.WideChar($D800 or ((C - $10000) shr 10));
|
|
|
|
- Inc(DestI);
|
|
|
|
- if DestI >= DestWideCharCount then Break;
|
|
|
|
- Dest[DestI] := System.WideChar($DC00 or ((C - $10000) and %0000001111111111));
|
|
|
|
- Inc(DestI);
|
|
|
|
- end
|
|
|
|
- else // invalid character, assume triple byte UTF-8 char
|
|
|
|
- if InvalidCharError(3) then Exit(trInvalidChar);
|
|
|
|
- end;
|
|
|
|
- end;
|
|
|
|
- end;
|
|
|
|
- end;
|
|
|
|
-
|
|
|
|
- if DestI >= DestWideCharCount then
|
|
|
|
- begin
|
|
|
|
- DestI := DestWideCharCount - 1;
|
|
|
|
- Result := trDestExhausted;
|
|
|
|
- end
|
|
|
|
- else
|
|
|
|
- Result := trNoError;
|
|
|
|
-
|
|
|
|
- Dest[DestI] := #0;
|
|
|
|
- ActualWideCharCount := DestI + 1;
|
|
|
|
-end;
|
|
|
|
-
|
|
|
|
-function UTF8ToUTF16(const P: PChar; ByteCnt: SizeUInt): UnicodeString;
|
|
|
|
-var
|
|
|
|
- L: SizeUInt;
|
|
|
|
-begin
|
|
|
|
- if ByteCnt=0 then
|
|
|
|
- exit('');
|
|
|
|
- SetLength(Result, ByteCnt);
|
|
|
|
- // wide chars of UTF-16 <= bytes of UTF-8 string
|
|
|
|
- if ConvertUTF8ToUTF16(PWideChar(Result), Length(Result) + 1, P, ByteCnt,
|
|
|
|
- [toInvalidCharToSymbol], L) = trNoError
|
|
|
|
- then SetLength(Result, L - 1)
|
|
|
|
- else Result := '';
|
|
|
|
-end;
|
|
|
|
-
|
|
|
|
-function UTF8ToUTF16(const S: AnsiString): UnicodeString;
|
|
|
|
-begin
|
|
|
|
- Result:=UTF8ToUTF16(PChar(S),length(S));
|
|
|
|
-end;
|
|
|
|
-
|
|
|
|
function StrToUTF16Hex(const AValue: UnicodeString; AIncludeBOM: boolean = True): AnsiString;
|
|
function StrToUTF16Hex(const AValue: UnicodeString; AIncludeBOM: boolean = True): AnsiString;
|
|
var
|
|
var
|
|
pc: ^Word;
|
|
pc: ^Word;
|
|
@@ -618,6 +380,11 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+procedure FillMem(Dest: pointer; Size: longint; Data: Byte );
|
|
|
|
+begin
|
|
|
|
+ FillChar(Dest^, Size, Data);
|
|
|
|
+end;
|
|
|
|
+
|
|
function TTFFileInfo.ReadULong(AStream: TStream): Longword;inline;
|
|
function TTFFileInfo.ReadULong(AStream: TStream): Longword;inline;
|
|
begin
|
|
begin
|
|
Result:=0;
|
|
Result:=0;
|
|
@@ -755,7 +522,7 @@ begin
|
|
While (UE>=0) and ((FSubtables[UE].PlatformID<>3) or (FSubtables[UE].EncodingID<> 1)) do
|
|
While (UE>=0) and ((FSubtables[UE].PlatformID<>3) or (FSubtables[UE].EncodingID<> 1)) do
|
|
Dec(UE);
|
|
Dec(UE);
|
|
if (UE=-1) then
|
|
if (UE=-1) then
|
|
- Raise ETTF.Create('No Format 4 map (unicode) table found');
|
|
|
|
|
|
+ Raise ETTF.Create('No Format 4 map (unicode) table found <'+FFileName + ' - ' + PostScriptName+'>');
|
|
TT:=TableStartPos+FSubtables[UE].Offset;
|
|
TT:=TableStartPos+FSubtables[UE].Offset;
|
|
AStream.Position:=TT;
|
|
AStream.Position:=TT;
|
|
FUnicodeMap.Format:= ReadUShort(AStream); // 2 bytes - Format of subtable
|
|
FUnicodeMap.Format:= ReadUShort(AStream); // 2 bytes - Format of subtable
|
|
@@ -839,12 +606,8 @@ begin
|
|
StringOffset:=ReadUShort(AStream); // 2 bytes
|
|
StringOffset:=ReadUShort(AStream); // 2 bytes
|
|
E := FNameEntries;
|
|
E := FNameEntries;
|
|
SetLength(E,Count);
|
|
SetLength(E,Count);
|
|
|
|
+ FillMem(@N, SizeOf(TNameRecord), 0);
|
|
// Read Descriptors
|
|
// Read Descriptors
|
|
-{$IFDEF VER3}
|
|
|
|
- N := Default(TNameRecord);
|
|
|
|
-{$ELSE}
|
|
|
|
- FillChar(N,SizeOf(TNameRecord),0);
|
|
|
|
-{$ENDIF}
|
|
|
|
for I:=0 to Count-1 do
|
|
for I:=0 to Count-1 do
|
|
begin
|
|
begin
|
|
AStream.ReadBuffer(N,SizeOf(TNameRecord));
|
|
AStream.ReadBuffer(N,SizeOf(TNameRecord));
|
|
@@ -1027,7 +790,7 @@ begin
|
|
ttcmap: ParseCmap(AStream);
|
|
ttcmap: ParseCmap(AStream);
|
|
ttname: ParseName(AStream);
|
|
ttname: ParseName(AStream);
|
|
ttos2 : ParseOS2(AStream);
|
|
ttos2 : ParseOS2(AStream);
|
|
- ttPost: ParsePost(AStream); // lecture table "Post"
|
|
|
|
|
|
+ ttPost: ParsePost(AStream);
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
@@ -1041,52 +804,17 @@ begin
|
|
raise ETTF.Create(rsFontEmbeddingNotAllowed);
|
|
raise ETTF.Create(rsFontEmbeddingNotAllowed);
|
|
PrepareEncoding(Encoding);
|
|
PrepareEncoding(Encoding);
|
|
// MissingWidth:=ToNatural(Widths[Chars[CharCodes^[32]]].AdvanceWidth); // Char(32) - Space character
|
|
// MissingWidth:=ToNatural(Widths[Chars[CharCodes^[32]]].AdvanceWidth); // Char(32) - Space character
|
|
- MissingWidth:=Widths[Chars[CharCodes^[32]]].AdvanceWidth; // Char(32) - Space character
|
|
|
|
|
|
+ FMissingWidth := Widths[Chars[CharCodes^[32]]].AdvanceWidth; // Char(32) - Space character
|
|
for I:=0 to 255 do
|
|
for I:=0 to 255 do
|
|
begin
|
|
begin
|
|
if (Widths[Chars[CharCodes^[i]]].AdvanceWidth> 0) and (CharNames^[i]<> '.notdef') then
|
|
if (Widths[Chars[CharCodes^[i]]].AdvanceWidth> 0) and (CharNames^[i]<> '.notdef') then
|
|
CharWidth[I]:= ToNatural(Widths[Chars[CharCodes^[I]]].AdvanceWidth)
|
|
CharWidth[I]:= ToNatural(Widths[Chars[CharCodes^[I]]].AdvanceWidth)
|
|
else
|
|
else
|
|
- CharWidth[I]:= MissingWidth;
|
|
|
|
- end;
|
|
|
|
-end;
|
|
|
|
-
|
|
|
|
-procedure TTFFileInfo.FillPDFFontDefinition(out ADef: TPDFFontDefinition; const AFontFile, AEncoding: String);
|
|
|
|
-
|
|
|
|
-Var
|
|
|
|
- I : Integer;
|
|
|
|
- S : String;
|
|
|
|
-
|
|
|
|
-begin
|
|
|
|
- ADef.FontType:='TrueType'; // DON'T LOCALIZE
|
|
|
|
- ADef.FontName:=PostScriptName;
|
|
|
|
- ADef.Ascender:=Ascender;
|
|
|
|
- ADef.Descender:=Descender;
|
|
|
|
- ADef.CapHeight:=Capheight;
|
|
|
|
- ADef.Flags:=Flags;
|
|
|
|
- For I:=0 to 3 do
|
|
|
|
- ADef.BBox[i]:=ToNatural(FHead.BBox[I]);
|
|
|
|
- ADef.ItalicAngle:=FPostScript.ItalicAngle;
|
|
|
|
- ADef.StemV:=StemV;
|
|
|
|
- ADef.MissingWidth:=MissingWidth;
|
|
|
|
- ADef.FontUp:=ToNatural(FPostScript.UnderlinePosition);
|
|
|
|
- ADef.FontUt:=ToNatural(FPostScript.UnderlineThickness);
|
|
|
|
- ADef.Encoding:=AEncoding;
|
|
|
|
- ADef.OriginalSize:=FOriginalSize;
|
|
|
|
- ADef.FontFile:=ChangeFileExt(AFontFile,'.z');
|
|
|
|
- if (Lowercase(AEncoding)<>'cp1252') then
|
|
|
|
- ADef.Diffs:=MakeDifferences;
|
|
|
|
- S:='';
|
|
|
|
- for I:=32 to 255 do
|
|
|
|
- begin
|
|
|
|
- if I>32 then
|
|
|
|
- S:=S+' ';
|
|
|
|
- S:=S+IntToStr(CharWidth[I]);
|
|
|
|
|
|
+ CharWidth[I]:= FMissingWidth;
|
|
end;
|
|
end;
|
|
- ADef.CharWidths:=S;
|
|
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TTFFileInfo.PrepareEncoding(const AEnCoding: String);
|
|
|
|
|
|
+procedure TTFFileInfo.PrepareEncoding(const AEncoding: String);
|
|
var
|
|
var
|
|
TE : TTTFEncoding;
|
|
TE : TTTFEncoding;
|
|
V : PTTFEncodingValues;
|
|
V : PTTFEncodingValues;
|
|
@@ -1098,49 +826,6 @@ begin
|
|
GetEncodingTables(Te,CharBase,V);
|
|
GetEncodingTables(Te,CharBase,V);
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TTFFileInfo.MakePDFFontDefinitionFile(const FontFile, Section, AEncoding: string);
|
|
|
|
-
|
|
|
|
-var
|
|
|
|
- Ini : TMemIniFile;
|
|
|
|
- S: String;
|
|
|
|
- I : Integer;
|
|
|
|
- Def : TPDFFontDefinition;
|
|
|
|
-
|
|
|
|
-begin
|
|
|
|
- FillPDFFontDefinition(Def,FontFile,AEncoding);
|
|
|
|
- Ini:=TMemIniFile.Create(FontFile);
|
|
|
|
- With Ini Do
|
|
|
|
- try
|
|
|
|
- WriteString(Section,'FontType',Def.FontType);
|
|
|
|
- WriteString(Section,'FontName',Def.FontName);
|
|
|
|
- WriteInteger(Section,'Ascent',Def.Ascender);
|
|
|
|
- WriteInteger(Section,'Descent',Def.Descender);
|
|
|
|
- WriteInteger(Section,'CapHeight',Def.CapHeight);
|
|
|
|
- WriteInteger(Section,'Flags',Def.Flags);
|
|
|
|
- S:='';
|
|
|
|
- for i:=0 to 3 do
|
|
|
|
- begin
|
|
|
|
- if I>0 then
|
|
|
|
- S:=S+' ';
|
|
|
|
- S:=S+IntToStr(Def.BBox[I]);
|
|
|
|
- end;
|
|
|
|
- WriteString(Section,'FontBBox',S);
|
|
|
|
- WriteInteger(Section,'ItalicAngle',Def.ItalicAngle);
|
|
|
|
- WriteInteger(Section,'StemV',Def.StemV);
|
|
|
|
- WriteInteger(Section,'MissingWidth',Def.MissingWidth);
|
|
|
|
- WriteInteger(Section,'FontUp',Def.FontUp);
|
|
|
|
- WriteInteger(Section,'FontUt',Def.FontUt);
|
|
|
|
- WriteString(Section,'Encoding',Def.Encoding);
|
|
|
|
- WriteString(Section,'FontFile',Def.FontFile);
|
|
|
|
- WriteInteger(Section,'OriginalSize',Def.OriginalSize);
|
|
|
|
- WriteString(Section,'Diffs',Def.Diffs);
|
|
|
|
- WriteString(Section,'CharWidth',Def.CharWidths);
|
|
|
|
- UpdateFile;
|
|
|
|
- finally
|
|
|
|
- Ini.Free;
|
|
|
|
- end;
|
|
|
|
-end;
|
|
|
|
-
|
|
|
|
function TTFFileInfo.MakeDifferences: String;
|
|
function TTFFileInfo.MakeDifferences: String;
|
|
var
|
|
var
|
|
i,l: Integer;
|
|
i,l: Integer;
|
|
@@ -1212,6 +897,24 @@ begin
|
|
Result := Widths[AIndex].AdvanceWidth;
|
|
Result := Widths[AIndex].AdvanceWidth;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+function TTFFileInfo.ItalicAngle: LongWord;
|
|
|
|
+begin
|
|
|
|
+ Result := FPostScript.ItalicAngle;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TTFFileInfo.BBox: string;
|
|
|
|
+var
|
|
|
|
+ i: integer;
|
|
|
|
+begin
|
|
|
|
+ Result := '';
|
|
|
|
+ for i := 0 to 3 do
|
|
|
|
+ begin
|
|
|
|
+ if i > 0 then
|
|
|
|
+ Result := Result + ' ';
|
|
|
|
+ Result := Result + IntToStr(ToNatural(FHead.BBox[I]));
|
|
|
|
+ end;
|
|
|
|
+end;
|
|
|
|
+
|
|
destructor TTFFileInfo.Destroy;
|
|
destructor TTFFileInfo.Destroy;
|
|
begin
|
|
begin
|
|
SetLength(FNameEntries, 0);
|
|
SetLength(FNameEntries, 0);
|
|
@@ -1228,6 +931,15 @@ begin
|
|
Result := round(d*10000);
|
|
Result := round(d*10000);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+function TTFFileInfo.GetMissingWidth: integer;
|
|
|
|
+begin
|
|
|
|
+ if FMissingWidth = 0 then
|
|
|
|
+ begin
|
|
|
|
+ FMissingWidth := Widths[Chars[CharCodes^[32]]].AdvanceWidth; // Char(32) - Space character
|
|
|
|
+ end;
|
|
|
|
+ Result := FMissingWidth;
|
|
|
|
+end;
|
|
|
|
+
|
|
function TTFFileInfo.IsNativeData: Boolean;
|
|
function TTFFileInfo.IsNativeData: Boolean;
|
|
begin
|
|
begin
|
|
Result:=False;
|
|
Result:=False;
|
|
@@ -1250,12 +962,4 @@ begin
|
|
Result := Result+64;
|
|
Result := Result+64;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TTFFileInfo.MakePDFFontDef(const FontFile: string; const Encoding:string; Embed: Boolean);
|
|
|
|
-begin
|
|
|
|
- PrepareFontDefinition(Encoding, Embed);
|
|
|
|
- MakePDFFontDefinitionFile(FontFile,PostScriptName,Encoding);
|
|
|
|
-end;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
end.
|
|
end.
|
|
-
|
|
|