大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> Script -> 让Fastreport3.x支持中文PDF的输出

让Fastreport3.x支持中文PDF的输出

时间: 2021-07-31 作者:daque

procedure tfrxpdffont.savetostream(stream: tstream);var  s: string;  b: tbitmap;  pm: ^outlinetextmetric;  fontname: string;  i: cardinal;  pfont: pchar;  firstchar, lastchar : integer;  memstream: tmemorystream;  memstream1: tmemorystream;  pwidths: pabc;  charset: tfontcharset;

  // support dbcs font name encoding  function encodefontname(afontname: string): string;  var    s: string;    index, len: integer;  begin    // add begin by ijia 2004.12.20    // 矫正在简体制统下繁体字体名的题目    // 只供给 mingliu, pmingliu --> 细明体, 新细明体的矫正    s:=uppercase(afontname);    if copy(s, 1, 7)='mingliu' then      afontname:='细明体';        if copy(s, 1, 8)='pmingliu' then      afontname:='新细明体';    // add end    s := '';    len := length(afontname);    index := 0;    while index < len do    begin      index := index + 1;      if byte(afontname[index]) > $7f then        s := s + '#' + inttohex(byte(afontname[index]), 2)      else        s := s + afontname[index];    end;    result := s;  end;

begin  inherited savetostream(stream);  b := tbitmap.create;  b.canvas.font.assign(font);  b.canvas.font.size := 750;  i := getoutlinetextmetrics(b.canvas.handle, 0, nil);  getmem(pm, i);  getoutlinetextmetrics(b.canvas.handle, i, pm);  firstchar := ord(pm.otmtextmetrics.tmfirstchar);  lastchar := ord(pm.otmtextmetrics.tmlastchar);  fontname := stringreplace(font.name, ' ', '#20', [rfreplaceall]);  s := '';  if fsbold in font.style then    s := s + 'bold';  if fsitalic in font.style then    s := s + 'italic';  if s <> '' then    fontname := fontname + ',' + s;

  charset := pm.otmtextmetrics.tmcharset;  // add by ijia 2004.12.20   //if charset = chinesebig5_charset then  if charset in [chinesebig5_charset, gb2312_charset] then    fontname := encodefontname(fontname)  else    fontname := parent.ptool.preparestring(fontname);

  parent.xrefadd(stream);  writeln(stream, inttostr(index + parent.fstartfonts) + ' 0 obj');  writeln(stream, '<<');  writeln(stream, '/type /font');  writeln(stream, '/name /f' + inttostr(index - 1));  writeln(stream, '/basefont /' + encodefontname(fontname));

  // add by ijia 2004.12.20  //if charset <> chinesebig5_charset then  if not (charset in [chinesebig5_charset, gb2312_charset]) then    writeln(stream, '/subtype /truetype')  else    writeln(stream, '/subtype /type0');

  case charset of    symbol_charset, ansi_charset:      writeln(stream, '/encoding /winansiencoding');

    russian_charset: {1251}    begin      writeln(stream, '/encoding <</type/encoding /baseencoding /winansiencoding');      write(stream, '/differences [129 /afii10052');      write(stream, '/quotesinglbase/afii10100/quotedblbase/ellipsis/dagger/daggerdbl/euro/perthousand/afii10058/guilsinglleft/afii10059/afii10061/afii10060/afii10145/afii10099/quoteleft');      write(stream, '/quoteright/quotedblleft/quotedblright/bullet/endash/emdash/space/trademark/afii10106/guilsinglright/afii10107/afii10109/afii10108/afii10193/space/afii10062');      write(stream, '/afii10110/afii10057/currency/afii10050/brokenbar/section/afii10023/copyright/afii10053/guillemotleft/logicalnot/hyphen/registered/afii10056/degree/plusminus');      write(stream, '/afii10055/afii10103/afii10098/mu/paragraph/periodcentered/afii10071/afii61352/afii10101/guillemotright/afii10105/afii10054/afii10102/afii10104/afii10017/afii10018');      write(stream, '/afii10019/afii10020/afii10021/afii10022/afii10024/afii10025/afii10026/afii10027/afii10028/afii10029/afii10030/afii10031/afii10032/afii10033/afii10034/afii10035');      write(stream, '/afii10036/afii10037/afii10038/afii10039/afii10040/afii10041/afii10042/afii10043/afii10044/afii10045/afii10046/afii10047/afii10048/afii10049/afii10065/afii10066');      write(stream, '/afii10067/afii10068/afii10069/afii10070/afii10072/afii10073/afii10074/afii10075/afii10076/afii10077/afii10078/afii10079/afii10080/afii10081/afii10082/afii10083');      writeln(stream, '/afii10084/afii10085/afii10086/afii10087/afii10088/afii10089/afii10090/afii10091/afii10092/afii10093/afii10094/afii10095/afii10096/afii10097/space]');      writeln(stream, '>>');    end;

    easteurope_charset: {1250}    begin      writeln(stream, '/encoding <</type/encoding /baseencoding /winansiencoding');      write(stream, '/differences [128 /euro 140 /sacute /tcaron /zcaron /zacute');      write(stream, ' 156 /sacute /tcaron /zcaron /zacute 161 /caron /breve /lslash');      write(stream, ' 165 /aogonek 170 /scedilla 175 /zdotaccent 178 /ogonek /lslash');      write(stream, ' 185 /aogonek /scedilla 188 /lcaron /hungarumlaut /lcaron /zdotaccent /racute');      write(stream, ' 195 /abreve 197 /lacute /cacute 200 /ccaron 202 /eogonek 204 /ecaron 207 /dcaron /dslash');      write(stream, ' 209 /nacute /ncaron /oacute 213 /ohungarumlaut 216 /rcaron /uring 219 /uhungarumlaut');      write(stream, ' 222 /tcedilla 224 /racute 227 /abreve 229 /lacute /cacute /ccedilla /ccaron');      write(stream, ' 234 /eogonek 236 /ecaron 239 /dcaron /dmacron /nacute /ncaron 245 /ohungarumlaut');      write(stream, ' 248 /rcaron /uring 251 /uhungarumlaut 254 /tcedilla /dotaccent]');      writeln(stream, '>>');    end;

    turkish_charset,    greek_charset,    hebrew_charset,    arabic_charset,    vietnamese_charset:    begin      writeln(stream, '/encoding <</type/encoding /baseencoding /winansiencoding');      write(stream, '/differences [128 /euro 142 /zcaron 158 /zcaron]');      writeln(stream, '>>');    end;

    chinesebig5_charset: {136}    begin      writeln(stream, '/descendantfonts [' + inttostr(index + 1 + parent.fstartfonts) + ' 0 r]');      writeln(stream, '/encoding /etenms-b5-h');      writeln(stream, '>>');      writeln(stream, 'endobj');

      writeln(stream, inttostr(index + 1 + parent.fstartfonts) + ' 0 obj');      writeln(stream, '<<');      writeln(stream, '/type /font');      writeln(stream, '/subtype');      writeln(stream, '/cidfonttype2');      writeln(stream, '/basefont /'+ encodefontname(fontname));      writeln(stream, '/wincharset 136');      writeln(stream, '/fontdescriptor ' + inttostr(index + 2 + parent.fstartfonts) + ' 0 r');      writeln(stream, '/cidsysteminfo');      writeln(stream, '<<');      writeln(stream, '/registry(adobe)');      writeln(stream, '/ordering(cns1)');      writeln(stream, '/supplement 0');      writeln(stream, '>>');      writeln(stream, '/dw 1000');      writeln(stream, '/w [1 95 500]');      writeln(stream, '>>');      writeln(stream, 'endobj');

      parent.xrefadd(stream);

      writeln(stream, inttostr(index + 2 + parent.fstartfonts) + ' 0 obj');      writeln(stream, '<<');      writeln(stream, '/type /fontdescriptor');      if parent.fembedded then         writeln(stream, '/fontfile2 ' + inttostr(index + 4 + parent.fstartfonts) + ' 0 r');      writeln(stream, '/fontname /' + encodefontname(fontname));      writeln(stream, '/flags 7');      writeln(stream, '/fontbbox [' + inttostr(pm^.otmrcfontbox.left) + ' '+ inttostr(pm^.otmrcfontbox.bottom) + ' '+ inttostr(pm^.otmrcfontbox.right) + ' '+ inttostr(pm^.otmrcfontbox.top) + ' ]');      writeln(stream, '/style << /panose <010502020300000000000000> >>');      writeln(stream, '/ascent ' + inttostr(pm^.otmascent));      writeln(stream, '/descent ' + inttostr(pm^.otmdescent));      writeln(stream, '/capheight ' + inttostr(pm^.otmtextmetrics.tmheight));      writeln(stream, '/stemv ' + inttostr(50 + round(sqr(pm^.otmtextmetrics.tmweight / 65))));      writeln(stream, '/italicangle ' + inttostr(pm^.otmitalicangle));      writeln(stream, '>>');      writeln(stream, 'endobj');    end;        // add begin by ijia 2004.12.20    gb2312_charset: {134}    begin      writeln(stream, '/descendantfonts [' + inttostr(index + 1 + parent.fstartfonts) + ' 0 r]');      writeln(stream, '/encoding /gb-euc-h');      writeln(stream, '>>');      writeln(stream, 'endobj');

      writeln(stream, inttostr(index + 1 + parent.fstartfonts) + ' 0 obj');      writeln(stream, '<<');      writeln(stream, '/type /font');      writeln(stream, '/subtype');      writeln(stream, '/cidfonttype2');      writeln(stream, '/basefont /'+ encodefontname(fontname));      writeln(stream, '/wincharset 134');      writeln(stream, '/fontdescriptor ' + inttostr(index + 2 + parent.fstartfonts) + ' 0 r');      writeln(stream, '/cidsysteminfo');      writeln(stream, '<<');      writeln(stream, '/registry(adobe)');      writeln(stream, '/ordering(gb1)');      writeln(stream, '/supplement 2');      writeln(stream, '>>');      writeln(stream, '/dw 1000');      writeln(stream, '/w [ 1 95 500 814 939 500 7712 [ 500 ] 7716 [ 500 ] ]');      writeln(stream, '>>');      writeln(stream, 'endobj');

      parent.xrefadd(stream);

      writeln(stream, inttostr(index + 2 + parent.fstartfonts) + ' 0 obj');      writeln(stream, '<<');      writeln(stream, '/type /fontdescriptor');      if parent.fembedded then         writeln(stream, '/fontfile2 ' + inttostr(index + 4 + parent.fstartfonts) + ' 0 r');      writeln(stream, '/fontname /' + encodefontname(fontname));      writeln(stream, '/flags 6');            writeln(stream, '/fontbbox [-25 -254 1000 880]');      writeln(stream, '/style << /panose <010502020400000000000000> >>');      writeln(stream, '/ascent 880');      writeln(stream, '/descent -120');      writeln(stream, '/capheight 880');      writeln(stream, '/stemv 93');      writeln(stream, '/italicangle 0');      writeln(stream, '>>');      writeln(stream, 'endobj');    end;    // add end  end;

  // add by ijia 2004.12.20   //if charset <> chinesebig5_charset then  if not (charset in [chinesebig5_charset, gb2312_charset]) then  begin    writeln(stream, '/fontdescriptor ' + inttostr(index + 2 + parent.fstartfonts) + ' 0 r');    writeln(stream, '/firstchar ' + inttostr(firstchar));    writeln(stream, '/lastchar ' + inttostr(lastchar));    getmem(pwidths, sizeof(abcarray));    write(stream, '/widths [');    getcharabcwidths(b.canvas.handle, firstchar, lastchar, pwidths^);    for i := 0 to (lastchar - firstchar) do      write(stream, inttostr(pwidths^[i].abca + integer(pwidths^[i].abcb) + pwidths^[i].abcc) + ' ');    writeln(stream, ']');    freemem(pwidths);    writeln(stream, '>>');    writeln(stream, 'endobj');    parent.xrefadd(stream);    writeln(stream, inttostr(index + 2 + parent.fstartfonts) + ' 0 obj');    writeln(stream, '<<');    writeln(stream, '/type /fontdescriptor');    if parent.fembedded then      writeln(stream, '/fontfile2 ' + inttostr(index + 4 + parent.fstartfonts) + ' 0 r');    writeln(stream, '/fontbbox [' + inttostr(pm^.otmrcfontbox.left) + ' '+ inttostr(pm^.otmrcfontbox.bottom) + ' '+ inttostr(pm^.otmrcfontbox.right) + ' '+ inttostr(pm^.otmrcfontbox.top) + ' ]');    writeln(stream, '/fontname /' + fontname);    writeln(stream, '/flags 32');    writeln(stream, '/stemv ' + inttostr(50 + round(sqr(pm^.otmtextmetrics.tmweight / 65))));    writeln(stream, '/capheight ' + inttostr(pm^.otmtextmetrics.tmheight));    writeln(stream, '/ascent ' + inttostr(pm^.otmascent));    writeln(stream, '/descent ' + inttostr(pm^.otmdescent));    writeln(stream, '/italicangle ' + inttostr(pm^.otmitalicangle));    writeln(stream, '>>');    writeln(stream, 'endobj');  end;

  if parent.fembedded then  begin    parent.xrefadd(stream);    writeln(stream, inttostr(index + 4 + parent.fstartfonts) + ' 0 obj');    i := getfontdata(b.canvas.handle, 0, 0, nil, 1);    getmem(pfont, i);    i := getfontdata(b.canvas.handle, 0, 0, pfont, i);    memstream := tmemorystream.create;    memstream.write(pfont^, i);

    memstream1 := tmemorystream.create;    frxdeflatestream(memstream, memstream1, gzmax);    writeln(stream, '<< /length ' + inttostr(memstream1.size) + ' /filter /flatedecode /length1 ' + inttostr(memstream.size) + ' >>');    writeln(stream, 'stream');    stream.copyfrom(memstream1, 0);    memstream1.free;

    memstream.free;    freemem(pfont);    writeln(stream, '');    writeln(stream, 'endstream');    writeln(stream, 'endobj');  end;  freemem(pm);  b.free;end;

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.