PdfConverter/internal/DTPUtils.tsf

228 lines
4.7 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

unit DTPUtils;
interface
uses DTPPrimitiveRanges;
function Utf8CharLengthFromByte(byte: char): integer;
function IsChineseChar(str: utf8_string): boolean;
function IsChinesePunctuation(str: utf8_string): boolean;
type Point = class
public
function Create();
public
X: real;
Y: real;
end;
type Stack = class
public
function Create();
function Pop();
function Push(element: any);
function Empty(): boolean;
private
arr_: tableArray;
index_: integer;
end;
type FldType = class
public
function Create();
public
Page: boolean;
NumPages: boolean;
Quote: boolean;
PageRef: boolean;
end;
type FldStruct = class
public
function Create();
public
Type: FldType;
Arabic: boolean;
MergeFormat: boolean;
Status: integer; // 0: begin 1: separate 2: end
end;
type TrProperty = class
public
function Create();
public
TrPr: TrPrUnitDecorator;
Height: real;
end;
type Region = class
public
function Create();
public
BordersRange: BordersRange;
RangeArr: array of BasicRange;
end;
type SymbolMapper = class
class function SymbolChr(symbol: string): string;
class function ZapfDingbatsChr(str: string): string;
private
static symbol_chr_hash_: array of chr;
static zapfdingbats_chr_hash_: array of chr;
end;
implementation
function Utf8CharLengthFromByte(byte: char): integer;
begin
if (_and(ord(byte), 0b10000000)) = 0 then
return 1;
else if (_and(ord(byte), 0b11100000)) = 0b11000000 then
return 2;
else if (_and(ord(byte), 0b11110000)) = 0b11100000 then
return 3;
else if (_and(ord(byte), 0b11111000)) = 0b11110000 then
return 4;
end;
function IsChineseChar(str: utf8_string): boolean;
begin
unicode_str := utf8ToUnicode(str);
codepoint := ord(unicode_str[1]);
return (codepoint >= 0x4E00 && codepoint <= 0x9FFF) or
(codepoint >= 0x3400 && codepoint <= 0x4DBF) or
(codepoint >= 0x20000 && codepoint <= 0x2A6DF);
end;
function IsChinesePunctuation(str: utf8_string): boolean;
begin
unicode_str := utf8ToUnicode(str);
codepoint := ord(unicode_str[1]);
return (codepoint >= 0x3000 && codepoint <= 0x303F) or
(codepoint >= 0xFF00 && codepoint <= 0xFFEF) or
(codepoint = 0x2018 || codepoint = 0x2019) or
(codepoint = 0x201C || codepoint = 0x201D) or
(codepoint = 0x2026 || codepoint = 0x2027);
end;
// Point
function Point.Create();
begin
{self.}X := 0;
{self.}Y := 0;
end;
// Stack
function Stack.Create();
begin
arr_ := array();
index_ := 0;
end;
function Stack.Pop();
begin
if index_ = 0 then return nil;
index_--;
ret := arr_[index_];
arr_[index_] := nil;
return ret;
end;
function Stack.Push(element: any);
begin
arr_[index_++] := element;
end;
function Stack.Empty(): boolean;
begin
return index_ = 0;
end;
// FldType
function FldType.Create();
begin
{self.}Page := false;
{self.}NumPages := false;
{self.}Quote := false;
{self.}PageRef := false;
end;
// FldStruct
function FldStruct.Create();
begin
{self.}Type := new FldType();
{self.}Arabic := false;
{self.}MergeFormat := false;
{self.}Status := 0;
end;
// TrProperty
function TrProperty.Create();
begin
{self.}TrPr := nil;
{self.}Height := 0;
end;
// Region
function Region.Create();
begin
BordersRange := new DTPPrimitiveRanges.BordersRange();
RangeArr := array();
end
// SymbolMapper
class function SymbolMapper.SymbolChr(symbol: string);
begin
if ifnil(symbol_chr_hash_) then
begin
symbol_chr_hash_ := array(
"": chr(0x2D),
"α": chr(0x61),
"β": chr(0x62),
"ε": chr(0x65),
"γ": chr(0x67),
"π": chr(0x70),
"θ": chr(0x71),
"{": chr(0x7B),
"}": chr(0x7D),
"∞": chr(0xA5),
"f": chr(0xA6),
"±": chr(0xB1),
"×": chr(0xB4),
"∂": chr(0xB6),
"∏": chr(0xD5),
"〈": chr(0xE1),
"∑": chr(0xE5),
"⌊": chr(0xEB),
"〉": chr(0xF1),
"Į": chr(0xF2),
"⌋": chr(0xFB),
// "": chr(0x),
);
end
return symbol_chr_hash_[symbol];
end;
class function SymbolMapper.ZapfDingbatsChr(str: string): string;
begin
if ifnil(zapfdingbats_chr_hash_) then
begin
zapfdingbats_chr_hash_ := array(
"": chr(118),
"": chr(110),
"": chr(108),
"": chr(117),
"": chr(108),
"o": chr(109),
"": chr(110),
);
end
return zapfdingbats_chr_hash_[symbol];
end;
end.