项目符号采用`ZapfDingbats`字体

This commit is contained in:
csh 2024-11-13 17:40:46 +08:00
parent 003268fd40
commit 5652980a97
3 changed files with 38 additions and 30 deletions

View File

@ -122,7 +122,7 @@ begin
elements := sect_ware.Elements(); elements := sect_ware.Elements();
for _,element in elements do for _,element in elements do
begin begin
// if _ = 31 then break; // if _ = 8 then break;
// if _ = 3 then // if _ = 3 then
// println("_ = {}, xml_file_ = {}", _, xml_file_); // println("_ = {}, xml_file_ = {}", _, xml_file_);
if element.LocalName = "p" then {self.}TransformP(text_point_, element, w, lb); if element.LocalName = "p" then {self.}TransformP(text_point_, element, w, lb);
@ -208,15 +208,13 @@ end;
function TSDocxToPdf.InitSymbol(); function TSDocxToPdf.InitSymbol();
begin begin
symbol_ := array( symbol_ := array(
"": "※", "": chr(118),
"": "■", "": chr(110),
"": "●", "": chr(108),
"": "◆", "": chr(117),
"": chr(108),
"": "●", "o": chr(109),
"": "■", "": chr(110),
"": "●",
); );
end; end;

View File

@ -498,10 +498,15 @@ begin
a_word := text[pos : pos+num-1]; a_word := text[pos : pos+num-1];
word := utf8ToAnsi(a_word); word := utf8ToAnsi(a_word);
if num <> 1 and word = "?" then if num <> 1 and word = "?" then
word := utf8ToAnsi(docx_to_pdf_.GetSymbol(a_word)); begin
pos += num; word := docx_to_pdf_.GetSymbol(a_word);
if ifnil(word) then word := "u";
font_obj := docx_to_pdf_.Font.GetSymbolFont();
end
else begin
font_name := rpr.RFonts.EastAsia ? rpr.RFonts.EastAsia : rpr.RFonts.Ascii; font_name := rpr.RFonts.EastAsia ? rpr.RFonts.EastAsia : rpr.RFonts.Ascii;
font_obj := docx_to_pdf_.Font.GetCNSFont(font_name, rpr.B, rpr.I); font_obj := docx_to_pdf_.Font.GetCNSFont(font_name, rpr.B, rpr.I);
end
if not rpr.Sz.Val then rpr.Sz.Val := rpr.SzCs.Val ? rpr.SzCs.Val : docx_to_pdf_.Font.GetDefaultSz(); if not rpr.Sz.Val then rpr.Sz.Val := rpr.SzCs.Val ? rpr.SzCs.Val : docx_to_pdf_.Font.GetDefaultSz();
page_.PdfPage.SetFontAndSize(font_obj, rpr.Sz.Val); page_.PdfPage.SetFontAndSize(font_obj, rpr.Sz.Val);
word_width := page_.PdfPage.TextWidth(word); word_width := page_.PdfPage.TextWidth(word);
@ -512,6 +517,7 @@ begin
text_range.Width := word_width; text_range.Width := word_width;
range_array_[length(range_array_)] := text_range; range_array_[length(range_array_)] := text_range;
if ifarray(bookmark_array_[link]) then bookmark_array_[link] union= array(text_range); if ifarray(bookmark_array_[link]) then bookmark_array_[link] union= array(text_range);
pos += num;
end end
end; end;

View File

@ -1,18 +1,19 @@
type TSFontWare = class type TSFontWare = class
public public
function Create(pdf: PdfFile); function Create(pdf: PdfFile);
function GetFontByText(text: string; name: string; bold: boolean; italic: boolean); function GetFontByText(text: string; name: string; bold: boolean; italic: boolean): PdfFont;
function GetAsciiFont(name: string; bold: boolean; italic: boolean); function GetAsciiFont(name: string; bold: boolean; italic: boolean): PdfFont;
function GetCNSFont(name: string; bold: boolean; italic: boolean); function GetCNSFont(name: string; bold: boolean; italic: boolean): PdfFont;
function GetSymbolFont(): PdfFont;
function UseExternalFont(); function UseExternalFont();
function SetSubstitutionRules(source: string; target: string); function SetSubstitutionRules(source: string; target: string);
function SetDefaultSz(value: real); function SetDefaultSz(value: real);
function GetDefaultSz(); function GetDefaultSz(): real;
private private
function GetExternalFont(name:string; bold: boolean; italic: boolean); function GetExternalFont(name:string; bold: boolean; italic: boolean): PdfFont;
function GetBuiltInCNSFont(name:string; bold: boolean; italic: boolean); function GetBuiltInCNSFont(name:string; bold: boolean; italic: boolean): PdfFont;
function GetBuiltInAsciiFont(name:string; bold: boolean; italic: boolean); function GetBuiltInAsciiFont(name:string; bold: boolean; italic: boolean): PdfFont;
private private
[weakref]pdf_: PdfFile; [weakref]pdf_: PdfFile;
@ -71,7 +72,7 @@ begin
return font; return font;
end; end;
function TSFontWare.GetFontByText(text: string; name: string; bold: boolean; italic: boolean); function TSFontWare.GetFontByText(text: string; name: string; bold: boolean; italic: boolean): PdfFont;
begin begin
len := length(text); len := length(text);
if len > 1 then if len > 1 then
@ -80,12 +81,12 @@ begin
return {self.}GetAsciiFont(name, bold, italic); return {self.}GetAsciiFont(name, bold, italic);
end; end;
function TSFontWare.GetCNSFont(name: string; bold: boolean; italic: boolean); function TSFontWare.GetCNSFont(name: string; bold: boolean; italic: boolean): PdfFont;
begin begin
return use_built_in_font_ ? {self.}GetBuiltInCNSFont(name, bold, italic) : {self.}GetExternalFont(name, bold, italic); return use_built_in_font_ ? {self.}GetBuiltInCNSFont(name, bold, italic) : {self.}GetExternalFont(name, bold, italic);
end; end;
function TSFontWare.GetBuiltInCNSFont(name: string; bold: boolean; italic: boolean); function TSFontWare.GetBuiltInCNSFont(name: string; bold: boolean; italic: boolean): PdfFont;
begin begin
font_name := substitution_rules_[name]; font_name := substitution_rules_[name];
if ifnil(font_name) then font_name := "SimSun"; if ifnil(font_name) then font_name := "SimSun";
@ -95,16 +96,15 @@ begin
font_name += ",Bold"; font_name += ",Bold";
else if italic then else if italic then
font_name += ",Italic"; font_name += ",Italic";
font := pdf_.GetFont(font_name, "GBK-EUC-H"); return pdf_.GetFont(font_name, "GBK-EUC-H");
return font;
end; end;
function TSFontWare.GetAsciiFont(name: string; bold: boolean; italic: boolean); function TSFontWare.GetAsciiFont(name: string; bold: boolean; italic: boolean): PdfFont;
begin begin
return use_built_in_font_ ? {self.}GetBuiltInAsciiFont(name, bold, italic) : {self.}GetExternalFont(name, bold, italic); return use_built_in_font_ ? {self.}GetBuiltInAsciiFont(name, bold, italic) : {self.}GetExternalFont(name, bold, italic);
end; end;
function TSFontWare.GetBuiltInAsciiFont(name:string; bold: boolean; italic: boolean); function TSFontWare.GetBuiltInAsciiFont(name:string; bold: boolean; italic: boolean): PdfFont;
begin begin
font_name := substitution_rules_[name]; font_name := substitution_rules_[name];
if ifnil(font_name) then font_name := "Times-Roman"; if ifnil(font_name) then font_name := "Times-Roman";
@ -126,11 +126,15 @@ begin
else if italic then else if italic then
font_name += "Times-Italic"; font_name += "Times-Italic";
end end
font := pdf_.GetFont(font_name, ""); return pdf_.GetFont(font_name, "");
return font;
end; end;
function TSFontWare.SetSubstitutionRules(source: string; target: string); function TSFontWare.SetSubstitutionRules(source: string; target: string);
begin begin
substitution_rules_[source] := target; substitution_rules_[source] := target;
end; end;
function TSFontWare.GetSymbolFont(): PdfFont;
begin
return pdf_.GetFont("ZapfDingbats", "");
end;