----------------------------------------------------------------------- -- Extended PDF exporter in Lua for SciTE -- Version 0.9.7, 20070805 -- Based on SciTE_ExporterPDF.lua Version 0.9.1, 20040812 -- -- Adapted from SciTE sources (scite/src/Exporters.cxx CVS 20040723) -- by Kein-Hong Man (This is a straightforward -- conversion and so I decline to claim it as my own.) -- -- Copyright 1998-2007 by Neil Hodgson -- All Rights Reserved -- -- Permission to use, copy, modify, and distribute this software and -- its documentation for any purpose and without fee is hereby granted, -- provided that the above copyright notice appear in all copies and -- that both that copyright notice and this permission notice appear in -- supporting documentation. -- -- NEIL HODGSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -- INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN -- NO EVENT SHALL NEIL HODGSON BE LIABLE FOR ANY SPECIAL, INDIRECT OR -- CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS -- OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, -- NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION -- WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -- ----------------------------------------------------------------------- -- USAGE -- -- * Please see SciTELuaExporters.html for notes on how to get this -- exporter up and running. -- * Requires SciTE_ExportBase.lua to be loaded first. -- * Has been tested casually with these lexers: basic text, props, -- lua and cpp giving byte-for-byte identical output. -- * Line numbering addition with the following default properties: -- # boolean: 0=no line numbers (default), 1=line numbers -- export.pdf.linenumbers=0 -- # number: spaces after line numbers, default 2 -- export.pdf.linenumspacing=2 -- * Line spacing option with the following properties: -- # number: line spacing as a ratio of font height, default 1.2 -- export.pdf.linespacing=1.2 -- * Full wrapping option with the following properties: -- # boolean: 1=wrap long lines (default), 0=no wrapping -- export.pdf.wrap=1 -- * Wrapping is dumb, does not wrap at word boundaries. -- * Pairwise kerning option with the following properties: -- # boolean: 0=don't perform kerning (default), 1=do kerning -- export.pdf.kerning=0 -- * Kerning does not do ligatures at the moment. ----------------------------------------------------------------------- -- TODO -- -- * Not sure if correct kerning value is used when changing styles -- (especially when it involves italics) -- * Make it faster. Currently processes about 75KB/sec running font -- wrapping and kerning on an Athlon 2500+ -- * Restructure the exporter instead of hacking/patching it further ----------------------------------------------------------------------- ----------------------------------------------------------------------- -- a simple check to alert of namespace collision, but allows different -- files to define their own functions in the exporters table ----------------------------------------------------------------------- if exporters then if exporters.SaveToPDF then error("SciTE_ExporterPDF: exporters.SaveToPDF already defined") end else exporters = {} end ----------------------------------------------------------------------- -- Font width metrics for extended PDF exporter in Lua -- Mostly autogenerated from the standard PDF font metrics files, found -- in the Lout document batch processor. WARNING this is NOT standard -- AFM data!!! These tables have been rearranged for WinAnsiEncoding. -- See PDF 1.4 Appendix D. A few tweaks were made for completeness. -- Use a tool like GNU recode to convert between character sets. -- NOTE table indices start from 1 ----------------------------------------------------------------------- local WidthHelvetica = { 278, 278, 355, 556, 556, 889, 667, 191, -- 32 - 39 333, 333, 389, 584, 278, 333, 278, 278, -- 40 - 47 556, 556, 556, 556, 556, 556, 556, 556, -- 48 - 55 556, 556, 278, 278, 584, 584, 584, 556, -- 56 - 63 1015, 667, 667, 722, 722, 667, 611, 778, -- 64 - 71 722, 278, 500, 667, 556, 833, 722, 778, -- 72 - 79 667, 778, 722, 667, 611, 722, 667, 944, -- 80 - 87 667, 667, 611, 278, 278, 278, 469, 556, -- 88 - 95 333, 556, 556, 500, 556, 556, 278, 556, -- 96 - 103 556, 222, 222, 500, 222, 833, 556, 556, -- 104 - 111 556, 556, 333, 500, 278, 556, 500, 722, -- 112 - 119 500, 500, 500, 334, 260, 334, 584, 350, -- 120 - 127 556, 350, 222, 556, 333, 1000, 556, 556, -- 128 - 135 333, 1000, 667, 333, 1000, 350, 611, 350, -- 136 - 143 350, 222, 222, 333, 333, 350, 556, 1000, -- 144 - 151 333, 1000, 500, 333, 944, 350, 500, 667, -- 152 - 159 278, 333, 556, 556, 556, 556, 260, 556, -- 160 - 167 333, 737, 370, 556, 584, 584, 737, 333, -- 168 - 175 400, 584, 333, 333, 333, 556, 537, 278, -- 176 - 183 333, 333, 365, 556, 834, 834, 834, 611, -- 184 - 191 667, 667, 667, 667, 667, 667, 1000, 722, -- 192 - 199 667, 667, 667, 667, 278, 278, 278, 278, -- 200 - 207 722, 722, 778, 778, 778, 778, 778, 584, -- 208 - 215 778, 722, 722, 722, 722, 667, 667, 611, -- 216 - 223 556, 556, 556, 556, 556, 556, 889, 500, -- 224 - 231 556, 556, 556, 556, 278, 278, 278, 278, -- 232 - 239 556, 556, 556, 556, 556, 556, 556, 584, -- 240 - 247 611, 556, 556, 556, 556, 500, 556, 500, -- 248 - 255 } local KernHelvetica = { ["AC"] = -30, ["AG"] = -30, ["AO"] = -30, ["AQ"] = -30, ["AT"] = -120, ["AU"] = -50, ["AV"] = -70, ["AW"] = -50, ["AY"] = -100, ["Au"] = -30, ["Av"] = -40, ["Aw"] = -40, ["Ay"] = -40, ["BU"] = -10, ["B,"] = -20, ["B."] = -20, ["C,"] = -30, ["C."] = -30, ["DA"] = -40, ["DV"] = -70, ["DW"] = -40, ["DY"] = -90, ["D,"] = -70, ["D."] = -70, ["FA"] = -80, ["Fa"] = -50, ["F,"] = -150, ["Fe"] = -30, ["Fo"] = -30, ["F."] = -150, ["Fr"] = -45, ["JA"] = -20, ["Ja"] = -20, ["J,"] = -30, ["J."] = -30, ["Ju"] = -20, ["KO"] = -50, ["Ke"] = -40, ["Ko"] = -40, ["Ku"] = -30, ["Ky"] = -50, ["LT"] = -110, ["LV"] = -110, ["LW"] = -70, ["LY"] = -140, ["L\148"] = -140, ["L\146"] = -160, ["Ly"] = -30, ["OA"] = -20, ["OT"] = -40, ["OV"] = -50, ["OW"] = -30, ["OX"] = -60, ["OY"] = -70, ["O,"] = -40, ["O."] = -40, ["PA"] = -120, ["Pa"] = -40, ["P,"] = -180, ["Pe"] = -50, ["Po"] = -50, ["P."] = -180, ["QU"] = -10, ["RO"] = -20, ["RT"] = -30, ["RU"] = -40, ["RV"] = -50, ["RW"] = -30, ["RY"] = -50, ["S,"] = -20, ["S."] = -20, ["TA"] = -120, ["TO"] = -40, ["Ta"] = -120, ["T:"] = -20, ["T,"] = -120, ["Te"] = -120, ["T-"] = -140, ["To"] = -120, ["T."] = -120, ["Tr"] = -120, ["T;"] = -20, ["Tu"] = -120, ["Tw"] = -120, ["Ty"] = -120, ["UA"] = -40, ["U,"] = -40, ["U."] = -40, ["VA"] = -80, ["VG"] = -40, ["VO"] = -40, ["Va"] = -70, ["V:"] = -40, ["V,"] = -125, ["Ve"] = -80, ["V-"] = -80, ["Vo"] = -80, ["V."] = -125, ["V;"] = -40, ["Vu"] = -70, ["WA"] = -50, ["WO"] = -20, ["Wa"] = -40, ["W,"] = -80, ["We"] = -30, ["W-"] = -40, ["Wo"] = -30, ["W."] = -80, ["Wu"] = -30, ["Wy"] = -20, ["YA"] = -110, ["YO"] = -85, ["Ya"] = -140, ["Y:"] = -60, ["Y,"] = -140, ["Ye"] = -140, ["Y-"] = -140, ["Yi"] = -20, ["Yo"] = -140, ["Y."] = -140, ["Y;"] = -60, ["Yu"] = -110, ["av"] = -20, ["aw"] = -20, ["ay"] = -30, ["bb"] = -10, ["b,"] = -40, ["bl"] = -20, ["b."] = -40, ["bu"] = -20, ["bv"] = -20, ["by"] = -20, ["c,"] = -15, ["ck"] = -20, [":\160"] = -50, [",\148"] = -100, [",\146"] = -100, ["e,"] = -15, ["e."] = -15, ["ev"] = -30, ["ew"] = -20, ["ex"] = -30, ["ey"] = -20, ["fa"] = -30, ["f,"] = -30, ["fe"] = -30, ["fo"] = -30, ["f."] = -30, ["f\148"] = 60, ["f\146"] = 50, ["gr"] = -10, ["hy"] = -30, ["ke"] = -20, ["ko"] = -20, ["mu"] = -10, ["my"] = -15, ["nu"] = -10, ["nv"] = -20, ["ny"] = -15, ["o,"] = -40, ["o."] = -40, ["ov"] = -15, ["ow"] = -15, ["ox"] = -30, ["oy"] = -30, ["\248\97"] = -55, ["\248\98"] = -55, ["\248\99"] = -55, ["\248\44"] = -95, ["\248\100"] = -55, ["\248\101"] = -55, ["\248\102"] = -55, ["\248\103"] = -55, ["\248\104"] = -55, ["\248\105"] = -55, ["\248\106"] = -55, ["\248\107"] = -55, ["\248\108"] = -55, ["\248\109"] = -55, ["\248\110"] = -55, ["\248\111"] = -55, ["\248\112"] = -55, ["\248\46"] = -95, ["\248\113"] = -55, ["\248\114"] = -55, ["\248\115"] = -55, ["\248\116"] = -55, ["\248\117"] = -55, ["\248\118"] = -70, ["\248\119"] = -70, ["\248\120"] = -85, ["\248\121"] = -70, ["\248\122"] = -55, ["p,"] = -35, ["p."] = -35, ["py"] = -30, [".\148"] = -100, [".\146"] = -100, [".\160"] = -60, ["\148\160"] = -40, ["\145\145"] = -57, ["\146\100"] = -50, ["\146\146"] = -57, ["\146\114"] = -50, ["\146\115"] = -50, ["\146\160"] = -70, ["ra"] = -10, ["r:"] = 30, ["r,"] = -50, ["ri"] = 15, ["rk"] = 15, ["rl"] = 15, ["rm"] = 25, ["rn"] = 25, ["rp"] = 30, ["r."] = -50, ["r;"] = 30, ["rt"] = 40, ["ru"] = 15, ["rv"] = 30, ["ry"] = 30, ["s,"] = -15, ["s."] = -15, ["sw"] = -30, [";\160"] = -50, ["\160\84"] = -50, ["\160\86"] = -50, ["\160\87"] = -40, ["\160\89"] = -90, ["\160\147"] = -30, ["\160\145"] = -60, ["va"] = -25, ["v,"] = -80, ["ve"] = -25, ["vo"] = -25, ["v."] = -80, ["wa"] = -15, ["w,"] = -60, ["we"] = -10, ["wo"] = -10, ["w."] = -60, ["xe"] = -30, ["ya"] = -20, ["y,"] = -100, ["ye"] = -20, ["yo"] = -20, ["y."] = -100, ["ze"] = -15, ["zo"] = -15, } local WidthHelveticaB = { 278, 333, 474, 556, 556, 889, 722, 238, -- 32 - 39 333, 333, 389, 584, 278, 333, 278, 278, -- 40 - 47 556, 556, 556, 556, 556, 556, 556, 556, -- 48 - 55 556, 556, 333, 333, 584, 584, 584, 611, -- 56 - 63 975, 722, 722, 722, 722, 667, 611, 778, -- 64 - 71 722, 278, 556, 722, 611, 833, 722, 778, -- 72 - 79 667, 778, 722, 667, 611, 722, 667, 944, -- 80 - 87 667, 667, 611, 333, 278, 333, 584, 556, -- 88 - 95 333, 556, 611, 556, 611, 556, 333, 611, -- 96 - 103 611, 278, 278, 556, 278, 889, 611, 611, -- 104 - 111 611, 611, 389, 556, 333, 611, 556, 778, -- 112 - 119 556, 556, 500, 389, 280, 389, 584, 350, -- 120 - 127 556, 350, 278, 556, 500, 1000, 556, 556, -- 128 - 135 333, 1000, 667, 333, 1000, 350, 611, 350, -- 136 - 143 350, 278, 278, 500, 500, 350, 556, 1000, -- 144 - 151 333, 1000, 556, 333, 944, 350, 500, 667, -- 152 - 159 278, 333, 556, 556, 556, 556, 280, 556, -- 160 - 167 333, 737, 370, 556, 584, 584, 737, 333, -- 168 - 175 400, 584, 333, 333, 333, 611, 556, 278, -- 176 - 183 333, 333, 365, 556, 834, 834, 834, 611, -- 184 - 191 722, 722, 722, 722, 722, 722, 1000, 722, -- 192 - 199 667, 667, 667, 667, 278, 278, 278, 278, -- 200 - 207 722, 722, 778, 778, 778, 778, 778, 584, -- 208 - 215 778, 722, 722, 722, 722, 667, 667, 611, -- 216 - 223 556, 556, 556, 556, 556, 556, 889, 556, -- 224 - 231 556, 556, 556, 556, 278, 278, 278, 278, -- 232 - 239 611, 611, 611, 611, 611, 611, 611, 584, -- 240 - 247 611, 611, 611, 611, 611, 556, 611, 556, -- 248 - 255 } local KernHelveticaB = { ["AC"] = -40, ["AG"] = -50, ["AO"] = -40, ["AQ"] = -40, ["AT"] = -90, ["AU"] = -50, ["AV"] = -80, ["AW"] = -60, ["AY"] = -110, ["Au"] = -30, ["Av"] = -40, ["Aw"] = -30, ["Ay"] = -30, ["BA"] = -30, ["BU"] = -10, ["DA"] = -40, ["DV"] = -40, ["DW"] = -40, ["DY"] = -70, ["D,"] = -30, ["D."] = -30, ["FA"] = -80, ["Fa"] = -20, ["F,"] = -100, ["F."] = -100, ["JA"] = -20, ["J,"] = -20, ["J."] = -20, ["Ju"] = -20, ["KO"] = -30, ["Ke"] = -15, ["Ko"] = -35, ["Ku"] = -30, ["Ky"] = -40, ["LT"] = -90, ["LV"] = -110, ["LW"] = -80, ["LY"] = -120, ["L\148"] = -140, ["L\146"] = -140, ["Ly"] = -30, ["OA"] = -50, ["OT"] = -40, ["OV"] = -50, ["OW"] = -50, ["OX"] = -50, ["OY"] = -70, ["O,"] = -40, ["O."] = -40, ["PA"] = -100, ["Pa"] = -30, ["P,"] = -120, ["Pe"] = -30, ["Po"] = -40, ["P."] = -120, ["QU"] = -10, ["Q,"] = 20, ["Q."] = 20, ["RO"] = -20, ["RT"] = -20, ["RU"] = -20, ["RV"] = -50, ["RW"] = -40, ["RY"] = -50, ["TA"] = -90, ["TO"] = -40, ["Ta"] = -80, ["T:"] = -40, ["T,"] = -80, ["Te"] = -60, ["T-"] = -120, ["To"] = -80, ["T."] = -80, ["Tr"] = -80, ["T;"] = -40, ["Tu"] = -90, ["Tw"] = -60, ["Ty"] = -60, ["UA"] = -50, ["U,"] = -30, ["U."] = -30, ["VA"] = -80, ["VG"] = -50, ["VO"] = -50, ["Va"] = -60, ["V:"] = -40, ["V,"] = -120, ["Ve"] = -50, ["V-"] = -80, ["Vo"] = -90, ["V."] = -120, ["V;"] = -40, ["Vu"] = -60, ["WA"] = -60, ["WO"] = -20, ["Wa"] = -40, ["W:"] = -10, ["W,"] = -80, ["We"] = -35, ["W-"] = -40, ["Wo"] = -60, ["W."] = -80, ["W;"] = -10, ["Wu"] = -45, ["Wy"] = -20, ["YA"] = -110, ["YO"] = -70, ["Ya"] = -90, ["Y:"] = -50, ["Y,"] = -100, ["Ye"] = -80, ["Yo"] = -100, ["Y."] = -100, ["Y;"] = -50, ["Yu"] = -100, ["ag"] = -10, ["av"] = -15, ["aw"] = -15, ["ay"] = -20, ["bl"] = -10, ["bu"] = -20, ["bv"] = -20, ["by"] = -20, ["ch"] = -10, ["ck"] = -20, ["cl"] = -20, ["cy"] = -10, [":\160"] = -40, [",\148"] = -120, [",\146"] = -120, [",\160"] = -40, ["dd"] = -10, ["dv"] = -15, ["dw"] = -15, ["dy"] = -15, ["e,"] = 10, ["e."] = 20, ["ev"] = -15, ["ew"] = -15, ["ex"] = -15, ["ey"] = -15, ["f,"] = -10, ["fe"] = -10, ["fo"] = -20, ["f."] = -10, ["f\148"] = 30, ["f\146"] = 30, ["ge"] = 10, ["gg"] = -10, ["hy"] = -20, ["ko"] = -15, ["lw"] = -15, ["ly"] = -15, ["mu"] = -20, ["my"] = -30, ["nu"] = -10, ["nv"] = -40, ["ny"] = -20, ["ov"] = -20, ["ow"] = -15, ["ox"] = -30, ["oy"] = -20, ["py"] = -15, [".\148"] = -120, [".\146"] = -120, [".\160"] = -40, ["\148\160"] = -80, ["\145\145"] = -46, ["\146\100"] = -80, ["\146\108"] = -20, ["\146\146"] = -46, ["\146\114"] = -40, ["\146\115"] = -60, ["\146\160"] = -80, ["\146\118"] = -20, ["rc"] = -20, ["r,"] = -60, ["rd"] = -20, ["rg"] = -15, ["r-"] = -20, ["ro"] = -20, ["r."] = -60, ["rq"] = -20, ["rs"] = -15, ["rt"] = 20, ["rv"] = 10, ["ry"] = 10, ["sw"] = -15, [";\160"] = -40, ["\160\84"] = -100, ["\160\86"] = -80, ["\160\87"] = -80, ["\160\89"] = -120, ["\160\147"] = -80, ["\160\145"] = -60, ["va"] = -20, ["v,"] = -80, ["vo"] = -30, ["v."] = -80, ["w,"] = -40, ["wo"] = -20, ["w."] = -40, ["xe"] = -10, ["ya"] = -30, ["y,"] = -80, ["ye"] = -10, ["yo"] = -25, ["y."] = -80, ["ze"] = 10, } local WidthHelveticaO = { 278, 278, 355, 556, 556, 889, 667, 191, -- 32 - 39 333, 333, 389, 584, 278, 333, 278, 278, -- 40 - 47 556, 556, 556, 556, 556, 556, 556, 556, -- 48 - 55 556, 556, 278, 278, 584, 584, 584, 556, -- 56 - 63 1015, 667, 667, 722, 722, 667, 611, 778, -- 64 - 71 722, 278, 500, 667, 556, 833, 722, 778, -- 72 - 79 667, 778, 722, 667, 611, 722, 667, 944, -- 80 - 87 667, 667, 611, 278, 278, 278, 469, 556, -- 88 - 95 333, 556, 556, 500, 556, 556, 278, 556, -- 96 - 103 556, 222, 222, 500, 222, 833, 556, 556, -- 104 - 111 556, 556, 333, 500, 278, 556, 500, 722, -- 112 - 119 500, 500, 500, 334, 260, 334, 584, 350, -- 120 - 127 556, 350, 222, 556, 333, 1000, 556, 556, -- 128 - 135 333, 1000, 667, 333, 1000, 350, 611, 350, -- 136 - 143 350, 222, 222, 333, 333, 350, 556, 1000, -- 144 - 151 333, 1000, 500, 333, 944, 350, 500, 667, -- 152 - 159 278, 333, 556, 556, 556, 556, 260, 556, -- 160 - 167 333, 737, 370, 556, 584, 584, 737, 333, -- 168 - 175 400, 584, 333, 333, 333, 556, 537, 278, -- 176 - 183 333, 333, 365, 556, 834, 834, 834, 611, -- 184 - 191 667, 667, 667, 667, 667, 667, 1000, 722, -- 192 - 199 667, 667, 667, 667, 278, 278, 278, 278, -- 200 - 207 722, 722, 778, 778, 778, 778, 778, 584, -- 208 - 215 778, 722, 722, 722, 722, 667, 667, 611, -- 216 - 223 556, 556, 556, 556, 556, 556, 889, 500, -- 224 - 231 556, 556, 556, 556, 278, 278, 278, 278, -- 232 - 239 556, 556, 556, 556, 556, 556, 556, 584, -- 240 - 247 611, 556, 556, 556, 556, 500, 556, 500, -- 248 - 255 } local KernHelveticaO = { ["AC"] = -30, ["AG"] = -30, ["AO"] = -30, ["AQ"] = -30, ["AT"] = -120, ["AU"] = -50, ["AV"] = -70, ["AW"] = -50, ["AY"] = -100, ["Au"] = -30, ["Av"] = -40, ["Aw"] = -40, ["Ay"] = -40, ["BU"] = -10, ["B,"] = -20, ["B."] = -20, ["C,"] = -30, ["C."] = -30, ["DA"] = -40, ["DV"] = -70, ["DW"] = -40, ["DY"] = -90, ["D,"] = -70, ["D."] = -70, ["FA"] = -80, ["Fa"] = -50, ["F,"] = -150, ["Fe"] = -30, ["Fo"] = -30, ["F."] = -150, ["Fr"] = -45, ["JA"] = -20, ["Ja"] = -20, ["J,"] = -30, ["J."] = -30, ["Ju"] = -20, ["KO"] = -50, ["Ke"] = -40, ["Ko"] = -40, ["Ku"] = -30, ["Ky"] = -50, ["LT"] = -110, ["LV"] = -110, ["LW"] = -70, ["LY"] = -140, ["L\148"] = -140, ["L\146"] = -160, ["Ly"] = -30, ["OA"] = -20, ["OT"] = -40, ["OV"] = -50, ["OW"] = -30, ["OX"] = -60, ["OY"] = -70, ["O,"] = -40, ["O."] = -40, ["PA"] = -120, ["Pa"] = -40, ["P,"] = -180, ["Pe"] = -50, ["Po"] = -50, ["P."] = -180, ["QU"] = -10, ["RO"] = -20, ["RT"] = -30, ["RU"] = -40, ["RV"] = -50, ["RW"] = -30, ["RY"] = -50, ["S,"] = -20, ["S."] = -20, ["TA"] = -120, ["TO"] = -40, ["Ta"] = -120, ["T:"] = -20, ["T,"] = -120, ["Te"] = -120, ["T-"] = -140, ["To"] = -120, ["T."] = -120, ["Tr"] = -120, ["T;"] = -20, ["Tu"] = -120, ["Tw"] = -120, ["Ty"] = -120, ["UA"] = -40, ["U,"] = -40, ["U."] = -40, ["VA"] = -80, ["VG"] = -40, ["VO"] = -40, ["Va"] = -70, ["V:"] = -40, ["V,"] = -125, ["Ve"] = -80, ["V-"] = -80, ["Vo"] = -80, ["V."] = -125, ["V;"] = -40, ["Vu"] = -70, ["WA"] = -50, ["WO"] = -20, ["Wa"] = -40, ["W,"] = -80, ["We"] = -30, ["W-"] = -40, ["Wo"] = -30, ["W."] = -80, ["Wu"] = -30, ["Wy"] = -20, ["YA"] = -110, ["YO"] = -85, ["Ya"] = -140, ["Y:"] = -60, ["Y,"] = -140, ["Ye"] = -140, ["Y-"] = -140, ["Yi"] = -20, ["Yo"] = -140, ["Y."] = -140, ["Y;"] = -60, ["Yu"] = -110, ["av"] = -20, ["aw"] = -20, ["ay"] = -30, ["bb"] = -10, ["b,"] = -40, ["bl"] = -20, ["b."] = -40, ["bu"] = -20, ["bv"] = -20, ["by"] = -20, ["c,"] = -15, ["ck"] = -20, [":\160"] = -50, [",\148"] = -100, [",\146"] = -100, ["e,"] = -15, ["e."] = -15, ["ev"] = -30, ["ew"] = -20, ["ex"] = -30, ["ey"] = -20, ["fa"] = -30, ["f,"] = -30, ["fe"] = -30, ["fo"] = -30, ["f."] = -30, ["f\148"] = 60, ["f\146"] = 50, ["gr"] = -10, ["hy"] = -30, ["ke"] = -20, ["ko"] = -20, ["mu"] = -10, ["my"] = -15, ["nu"] = -10, ["nv"] = -20, ["ny"] = -15, ["o,"] = -40, ["o."] = -40, ["ov"] = -15, ["ow"] = -15, ["ox"] = -30, ["oy"] = -30, ["\248\97"] = -55, ["\248\98"] = -55, ["\248\99"] = -55, ["\248\44"] = -95, ["\248\100"] = -55, ["\248\101"] = -55, ["\248\102"] = -55, ["\248\103"] = -55, ["\248\104"] = -55, ["\248\105"] = -55, ["\248\106"] = -55, ["\248\107"] = -55, ["\248\108"] = -55, ["\248\109"] = -55, ["\248\110"] = -55, ["\248\111"] = -55, ["\248\112"] = -55, ["\248\46"] = -95, ["\248\113"] = -55, ["\248\114"] = -55, ["\248\115"] = -55, ["\248\116"] = -55, ["\248\117"] = -55, ["\248\118"] = -70, ["\248\119"] = -70, ["\248\120"] = -85, ["\248\121"] = -70, ["\248\122"] = -55, ["p,"] = -35, ["p."] = -35, ["py"] = -30, [".\148"] = -100, [".\146"] = -100, [".\160"] = -60, ["\148\160"] = -40, ["\145\145"] = -57, ["\146\100"] = -50, ["\146\146"] = -57, ["\146\114"] = -50, ["\146\115"] = -50, ["\146\160"] = -70, ["ra"] = -10, ["r:"] = 30, ["r,"] = -50, ["ri"] = 15, ["rk"] = 15, ["rl"] = 15, ["rm"] = 25, ["rn"] = 25, ["rp"] = 30, ["r."] = -50, ["r;"] = 30, ["rt"] = 40, ["ru"] = 15, ["rv"] = 30, ["ry"] = 30, ["s,"] = -15, ["s."] = -15, ["sw"] = -30, [";\160"] = -50, ["\160\84"] = -50, ["\160\86"] = -50, ["\160\87"] = -40, ["\160\89"] = -90, ["\160\147"] = -30, ["\160\145"] = -60, ["va"] = -25, ["v,"] = -80, ["ve"] = -25, ["vo"] = -25, ["v."] = -80, ["wa"] = -15, ["w,"] = -60, ["we"] = -10, ["wo"] = -10, ["w."] = -60, ["xe"] = -30, ["ya"] = -20, ["y,"] = -100, ["ye"] = -20, ["yo"] = -20, ["y."] = -100, ["ze"] = -15, ["zo"] = -15, } local WidthHelveticaBO = { 278, 333, 474, 556, 556, 889, 722, 238, -- 32 - 39 333, 333, 389, 584, 278, 333, 278, 278, -- 40 - 47 556, 556, 556, 556, 556, 556, 556, 556, -- 48 - 55 556, 556, 333, 333, 584, 584, 584, 611, -- 56 - 63 975, 722, 722, 722, 722, 667, 611, 778, -- 64 - 71 722, 278, 556, 722, 611, 833, 722, 778, -- 72 - 79 667, 778, 722, 667, 611, 722, 667, 944, -- 80 - 87 667, 667, 611, 333, 278, 333, 584, 556, -- 88 - 95 333, 556, 611, 556, 611, 556, 333, 611, -- 96 - 103 611, 278, 278, 556, 278, 889, 611, 611, -- 104 - 111 611, 611, 389, 556, 333, 611, 556, 778, -- 112 - 119 556, 556, 500, 389, 280, 389, 584, 350, -- 120 - 127 556, 350, 278, 556, 500, 1000, 556, 556, -- 128 - 135 333, 1000, 667, 333, 1000, 350, 611, 350, -- 136 - 143 350, 278, 278, 500, 500, 350, 556, 1000, -- 144 - 151 333, 1000, 556, 333, 944, 350, 500, 667, -- 152 - 159 278, 333, 556, 556, 556, 556, 280, 556, -- 160 - 167 333, 737, 370, 556, 584, 584, 737, 333, -- 168 - 175 400, 584, 333, 333, 333, 611, 556, 278, -- 176 - 183 333, 333, 365, 556, 834, 834, 834, 611, -- 184 - 191 722, 722, 722, 722, 722, 722, 1000, 722, -- 192 - 199 667, 667, 667, 667, 278, 278, 278, 278, -- 200 - 207 722, 722, 778, 778, 778, 778, 778, 584, -- 208 - 215 778, 722, 722, 722, 722, 667, 667, 611, -- 216 - 223 556, 556, 556, 556, 556, 556, 889, 556, -- 224 - 231 556, 556, 556, 556, 278, 278, 278, 278, -- 232 - 239 611, 611, 611, 611, 611, 611, 611, 584, -- 240 - 247 611, 611, 611, 611, 611, 556, 611, 556, -- 248 - 255 } local KernHelveticaBO = { ["AC"] = -40, ["AG"] = -50, ["AO"] = -40, ["AQ"] = -40, ["AT"] = -90, ["AU"] = -50, ["AV"] = -80, ["AW"] = -60, ["AY"] = -110, ["Au"] = -30, ["Av"] = -40, ["Aw"] = -30, ["Ay"] = -30, ["BA"] = -30, ["BU"] = -10, ["DA"] = -40, ["DV"] = -40, ["DW"] = -40, ["DY"] = -70, ["D,"] = -30, ["D."] = -30, ["FA"] = -80, ["Fa"] = -20, ["F,"] = -100, ["F."] = -100, ["JA"] = -20, ["J,"] = -20, ["J."] = -20, ["Ju"] = -20, ["KO"] = -30, ["Ke"] = -15, ["Ko"] = -35, ["Ku"] = -30, ["Ky"] = -40, ["LT"] = -90, ["LV"] = -110, ["LW"] = -80, ["LY"] = -120, ["L\148"] = -140, ["L\146"] = -140, ["Ly"] = -30, ["OA"] = -50, ["OT"] = -40, ["OV"] = -50, ["OW"] = -50, ["OX"] = -50, ["OY"] = -70, ["O,"] = -40, ["O."] = -40, ["PA"] = -100, ["Pa"] = -30, ["P,"] = -120, ["Pe"] = -30, ["Po"] = -40, ["P."] = -120, ["QU"] = -10, ["Q,"] = 20, ["Q."] = 20, ["RO"] = -20, ["RT"] = -20, ["RU"] = -20, ["RV"] = -50, ["RW"] = -40, ["RY"] = -50, ["TA"] = -90, ["TO"] = -40, ["Ta"] = -80, ["T:"] = -40, ["T,"] = -80, ["Te"] = -60, ["T-"] = -120, ["To"] = -80, ["T."] = -80, ["Tr"] = -80, ["T;"] = -40, ["Tu"] = -90, ["Tw"] = -60, ["Ty"] = -60, ["UA"] = -50, ["U,"] = -30, ["U."] = -30, ["VA"] = -80, ["VG"] = -50, ["VO"] = -50, ["Va"] = -60, ["V:"] = -40, ["V,"] = -120, ["Ve"] = -50, ["V-"] = -80, ["Vo"] = -90, ["V."] = -120, ["V;"] = -40, ["Vu"] = -60, ["WA"] = -60, ["WO"] = -20, ["Wa"] = -40, ["W:"] = -10, ["W,"] = -80, ["We"] = -35, ["W-"] = -40, ["Wo"] = -60, ["W."] = -80, ["W;"] = -10, ["Wu"] = -45, ["Wy"] = -20, ["YA"] = -110, ["YO"] = -70, ["Ya"] = -90, ["Y:"] = -50, ["Y,"] = -100, ["Ye"] = -80, ["Yo"] = -100, ["Y."] = -100, ["Y;"] = -50, ["Yu"] = -100, ["ag"] = -10, ["av"] = -15, ["aw"] = -15, ["ay"] = -20, ["bl"] = -10, ["bu"] = -20, ["bv"] = -20, ["by"] = -20, ["ch"] = -10, ["ck"] = -20, ["cl"] = -20, ["cy"] = -10, [":\160"] = -40, [",\148"] = -120, [",\146"] = -120, [",\160"] = -40, ["dd"] = -10, ["dv"] = -15, ["dw"] = -15, ["dy"] = -15, ["e,"] = 10, ["e."] = 20, ["ev"] = -15, ["ew"] = -15, ["ex"] = -15, ["ey"] = -15, ["f,"] = -10, ["fe"] = -10, ["fo"] = -20, ["f."] = -10, ["f\148"] = 30, ["f\146"] = 30, ["ge"] = 10, ["gg"] = -10, ["hy"] = -20, ["ko"] = -15, ["lw"] = -15, ["ly"] = -15, ["mu"] = -20, ["my"] = -30, ["nu"] = -10, ["nv"] = -40, ["ny"] = -20, ["ov"] = -20, ["ow"] = -15, ["ox"] = -30, ["oy"] = -20, ["py"] = -15, [".\148"] = -120, [".\146"] = -120, [".\160"] = -40, ["\148\160"] = -80, ["\145\145"] = -46, ["\146\100"] = -80, ["\146\108"] = -20, ["\146\146"] = -46, ["\146\114"] = -40, ["\146\115"] = -60, ["\146\160"] = -80, ["\146\118"] = -20, ["rc"] = -20, ["r,"] = -60, ["rd"] = -20, ["rg"] = -15, ["r-"] = -20, ["ro"] = -20, ["r."] = -60, ["rq"] = -20, ["rs"] = -15, ["rt"] = 20, ["rv"] = 10, ["ry"] = 10, ["sw"] = -15, [";\160"] = -40, ["\160\84"] = -100, ["\160\86"] = -80, ["\160\87"] = -80, ["\160\89"] = -120, ["\160\147"] = -80, ["\160\145"] = -60, ["va"] = -20, ["v,"] = -80, ["vo"] = -30, ["v."] = -80, ["w,"] = -40, ["wo"] = -20, ["w."] = -40, ["xe"] = -10, ["ya"] = -30, ["y,"] = -80, ["ye"] = -10, ["yo"] = -25, ["y."] = -80, ["ze"] = 10, } local WidthTimes = { 250, 333, 408, 500, 500, 833, 778, 180, -- 32 - 39 333, 333, 500, 564, 250, 333, 250, 278, -- 40 - 47 500, 500, 500, 500, 500, 500, 500, 500, -- 48 - 55 500, 500, 278, 278, 564, 564, 564, 444, -- 56 - 63 921, 722, 667, 667, 722, 611, 556, 722, -- 64 - 71 722, 333, 389, 722, 611, 889, 722, 722, -- 72 - 79 556, 722, 667, 556, 611, 722, 722, 944, -- 80 - 87 722, 722, 611, 333, 278, 333, 469, 500, -- 88 - 95 333, 444, 500, 444, 500, 444, 333, 500, -- 96 - 103 500, 278, 278, 500, 278, 778, 500, 500, -- 104 - 111 500, 500, 333, 389, 278, 500, 500, 722, -- 112 - 119 500, 500, 444, 480, 200, 480, 541, 350, -- 120 - 127 500, 350, 333, 500, 444, 1000, 500, 500, -- 128 - 135 333, 1000, 556, 333, 889, 350, 611, 350, -- 136 - 143 350, 333, 333, 444, 444, 350, 500, 1000, -- 144 - 151 333, 980, 389, 333, 722, 350, 444, 722, -- 152 - 159 250, 333, 500, 500, 500, 500, 200, 500, -- 160 - 167 333, 760, 276, 500, 564, 564, 760, 333, -- 168 - 175 400, 564, 300, 300, 333, 500, 453, 250, -- 176 - 183 333, 300, 310, 500, 750, 750, 750, 444, -- 184 - 191 722, 722, 722, 722, 722, 722, 889, 667, -- 192 - 199 611, 611, 611, 611, 333, 333, 333, 333, -- 200 - 207 722, 722, 722, 722, 722, 722, 722, 564, -- 208 - 215 722, 722, 722, 722, 722, 722, 556, 500, -- 216 - 223 444, 444, 444, 444, 444, 444, 667, 444, -- 224 - 231 444, 444, 444, 444, 278, 278, 278, 278, -- 232 - 239 500, 500, 500, 500, 500, 500, 500, 564, -- 240 - 247 500, 500, 500, 500, 500, 500, 500, 500, -- 248 - 255 } local KernTimes = { ["AC"] = -40, ["AG"] = -40, ["AO"] = -55, ["AQ"] = -55, ["AT"] = -111, ["AU"] = -55, ["AV"] = -135, ["AW"] = -90, ["AY"] = -105, ["A\146"] = -111, ["Av"] = -74, ["Aw"] = -92, ["Ay"] = -92, ["BA"] = -35, ["BU"] = -10, ["DA"] = -40, ["DV"] = -40, ["DW"] = -30, ["DY"] = -55, ["FA"] = -74, ["Fa"] = -15, ["F,"] = -80, ["Fo"] = -15, ["F."] = -80, ["JA"] = -60, ["KO"] = -30, ["Ke"] = -25, ["Ko"] = -35, ["Ku"] = -15, ["Ky"] = -25, ["LT"] = -92, ["LV"] = -100, ["LW"] = -74, ["LY"] = -100, ["L\146"] = -92, ["Ly"] = -55, ["NA"] = -35, ["OA"] = -35, ["OT"] = -40, ["OV"] = -50, ["OW"] = -35, ["OX"] = -40, ["OY"] = -50, ["PA"] = -92, ["Pa"] = -15, ["P,"] = -111, ["P."] = -111, ["QU"] = -10, ["RO"] = -40, ["RT"] = -60, ["RU"] = -40, ["RV"] = -80, ["RW"] = -55, ["RY"] = -65, ["TA"] = -93, ["TO"] = -18, ["Ta"] = -80, ["T:"] = -50, ["T,"] = -74, ["Te"] = -70, ["T-"] = -92, ["Ti"] = -35, ["To"] = -80, ["T."] = -74, ["Tr"] = -35, ["T;"] = -55, ["Tu"] = -45, ["Tw"] = -80, ["Ty"] = -80, ["UA"] = -40, ["VA"] = -135, ["VG"] = -15, ["VO"] = -40, ["Va"] = -111, ["V:"] = -74, ["V,"] = -129, ["Ve"] = -111, ["V-"] = -100, ["Vi"] = -60, ["Vo"] = -129, ["V."] = -129, ["V;"] = -74, ["Vu"] = -75, ["WA"] = -120, ["WO"] = -10, ["Wa"] = -80, ["W:"] = -37, ["W,"] = -92, ["We"] = -80, ["W-"] = -65, ["Wi"] = -40, ["Wo"] = -80, ["W."] = -92, ["W;"] = -37, ["Wu"] = -50, ["Wy"] = -73, ["YA"] = -120, ["YO"] = -30, ["Ya"] = -100, ["Y:"] = -92, ["Y,"] = -129, ["Ye"] = -100, ["Y-"] = -111, ["Yi"] = -55, ["Yo"] = -110, ["Y."] = -129, ["Y;"] = -92, ["Yu"] = -111, ["av"] = -20, ["aw"] = -15, ["b."] = -40, ["bu"] = -20, ["bv"] = -15, ["cy"] = -15, [",\148"] = -70, [",\146"] = -70, ["eg"] = -15, ["ev"] = -25, ["ew"] = -25, ["ex"] = -15, ["ey"] = -15, ["fa"] = -10, ["ff"] = -25, ["fi"] = -20, ["f\146"] = 55, ["ga"] = -5, ["hy"] = -5, ["iv"] = -25, ["ke"] = -10, ["ko"] = -10, ["ky"] = -15, ["lw"] = -10, ["nv"] = -40, ["ny"] = -15, ["ov"] = -15, ["ow"] = -25, ["oy"] = -10, ["py"] = -10, [".\148"] = -70, [".\146"] = -70, ["\147\65"] = -80, ["\145\65"] = -80, ["\145\145"] = -74, ["\146\100"] = -50, ["\146\108"] = -10, ["\146\146"] = -74, ["\146\114"] = -50, ["\146\115"] = -55, ["\146\160"] = -74, ["\146\116"] = -18, ["\146\118"] = -50, ["r,"] = -40, ["rg"] = -18, ["r-"] = -20, ["r."] = -55, ["\160\65"] = -55, ["\160\84"] = -18, ["\160\86"] = -50, ["\160\87"] = -30, ["\160\89"] = -90, ["va"] = -25, ["v,"] = -65, ["ve"] = -15, ["vo"] = -20, ["v."] = -65, ["wa"] = -10, ["w,"] = -65, ["wo"] = -10, ["w."] = -65, ["xe"] = -15, ["y,"] = -65, ["y."] = -65, } local WidthTimesB = { 250, 333, 555, 500, 500, 1000, 833, 278, -- 32 - 39 333, 333, 500, 570, 250, 333, 250, 278, -- 40 - 47 500, 500, 500, 500, 500, 500, 500, 500, -- 48 - 55 500, 500, 333, 333, 570, 570, 570, 500, -- 56 - 63 930, 722, 667, 722, 722, 667, 611, 778, -- 64 - 71 778, 389, 500, 778, 667, 944, 722, 778, -- 72 - 79 611, 778, 722, 556, 667, 722, 722, 1000, -- 80 - 87 722, 722, 667, 333, 278, 333, 581, 500, -- 88 - 95 333, 500, 556, 444, 556, 444, 333, 500, -- 96 - 103 556, 278, 333, 556, 278, 833, 556, 500, -- 104 - 111 556, 556, 444, 389, 333, 556, 500, 722, -- 112 - 119 500, 500, 444, 394, 220, 394, 520, 350, -- 120 - 127 500, 350, 333, 500, 500, 1000, 500, 500, -- 128 - 135 333, 1000, 556, 333, 1000, 350, 667, 350, -- 136 - 143 350, 333, 333, 500, 500, 350, 500, 1000, -- 144 - 151 333, 1000, 389, 333, 722, 350, 444, 722, -- 152 - 159 250, 333, 500, 500, 500, 500, 220, 500, -- 160 - 167 333, 747, 300, 500, 570, 570, 747, 333, -- 168 - 175 400, 570, 300, 300, 333, 556, 540, 250, -- 176 - 183 333, 300, 330, 500, 750, 750, 750, 500, -- 184 - 191 722, 722, 722, 722, 722, 722, 1000, 722, -- 192 - 199 667, 667, 667, 667, 389, 389, 389, 389, -- 200 - 207 722, 722, 778, 778, 778, 778, 778, 570, -- 208 - 215 778, 722, 722, 722, 722, 722, 611, 556, -- 216 - 223 500, 500, 500, 500, 500, 500, 722, 444, -- 224 - 231 444, 444, 444, 444, 278, 278, 278, 278, -- 232 - 239 500, 556, 500, 500, 500, 500, 500, 570, -- 240 - 247 500, 556, 556, 556, 556, 500, 556, 500, -- 248 - 255 } local KernTimesB = { ["AC"] = -55, ["AG"] = -55, ["AO"] = -45, ["AQ"] = -45, ["AT"] = -95, ["AU"] = -50, ["AV"] = -145, ["AW"] = -130, ["AY"] = -100, ["Ap"] = -25, ["A\146"] = -74, ["Au"] = -50, ["Av"] = -100, ["Aw"] = -90, ["Ay"] = -74, ["BA"] = -30, ["BU"] = -10, ["DA"] = -35, ["DV"] = -40, ["DW"] = -40, ["DY"] = -40, ["D."] = -20, ["FA"] = -90, ["Fa"] = -25, ["F,"] = -92, ["Fe"] = -25, ["Fo"] = -25, ["F."] = -110, ["JA"] = -30, ["Ja"] = -15, ["Je"] = -15, ["Jo"] = -15, ["J."] = -20, ["Ju"] = -15, ["KO"] = -30, ["Ke"] = -25, ["Ko"] = -25, ["Ku"] = -15, ["Ky"] = -45, ["LT"] = -92, ["LV"] = -92, ["LW"] = -92, ["LY"] = -92, ["L\148"] = -20, ["L\146"] = -110, ["Ly"] = -55, ["NA"] = -20, ["OA"] = -40, ["OT"] = -40, ["OV"] = -50, ["OW"] = -50, ["OX"] = -40, ["OY"] = -50, ["PA"] = -74, ["Pa"] = -10, ["P,"] = -92, ["Pe"] = -20, ["Po"] = -20, ["P."] = -110, ["QU"] = -10, ["Q."] = -20, ["RO"] = -30, ["RT"] = -40, ["RU"] = -30, ["RV"] = -55, ["RW"] = -35, ["RY"] = -35, ["TA"] = -90, ["TO"] = -18, ["Ta"] = -92, ["T:"] = -74, ["T,"] = -74, ["Te"] = -92, ["T-"] = -92, ["Ti"] = -18, ["To"] = -92, ["T."] = -90, ["Tr"] = -74, ["T;"] = -74, ["Tu"] = -92, ["Tw"] = -74, ["Ty"] = -74, ["UA"] = -60, ["U,"] = -50, ["U."] = -50, ["VA"] = -135, ["VG"] = -30, ["VO"] = -45, ["Va"] = -92, ["V:"] = -92, ["V,"] = -129, ["Ve"] = -100, ["V-"] = -74, ["Vi"] = -37, ["Vo"] = -100, ["V."] = -145, ["V;"] = -92, ["Vu"] = -92, ["WA"] = -120, ["WO"] = -10, ["Wa"] = -65, ["W:"] = -55, ["W,"] = -92, ["We"] = -65, ["W-"] = -37, ["Wi"] = -18, ["Wo"] = -75, ["W."] = -92, ["W;"] = -55, ["Wu"] = -50, ["Wy"] = -60, ["YA"] = -110, ["YO"] = -35, ["Ya"] = -85, ["Y:"] = -92, ["Y,"] = -92, ["Ye"] = -111, ["Y-"] = -92, ["Yi"] = -37, ["Yo"] = -111, ["Y."] = -92, ["Y;"] = -92, ["Yu"] = -92, ["av"] = -25, ["bb"] = -10, ["b."] = -40, ["bu"] = -20, ["bv"] = -15, [",\148"] = -45, [",\146"] = -55, ["dw"] = -15, ["ev"] = -15, ["f,"] = -15, ["fi"] = -25, ["fo"] = -25, ["f."] = -15, ["f\148"] = 50, ["f\146"] = 55, ["g."] = -15, ["hy"] = -15, ["iv"] = -10, ["ke"] = -10, ["ko"] = -15, ["ky"] = -15, ["nv"] = -40, ["ov"] = -10, ["ow"] = -10, [".\148"] = -55, [".\146"] = -55, ["\147\65"] = -10, ["\145\65"] = -10, ["\145\145"] = -63, ["\146\100"] = -20, ["\146\146"] = -63, ["\146\114"] = -20, ["\146\115"] = -37, ["\146\160"] = -74, ["\146\118"] = -20, ["rc"] = -18, ["r,"] = -92, ["re"] = -18, ["rg"] = -10, ["r-"] = -37, ["rn"] = -15, ["ro"] = -18, ["rp"] = -10, ["r."] = -100, ["rq"] = -18, ["rv"] = -10, ["\160\65"] = -55, ["\160\84"] = -30, ["\160\86"] = -45, ["\160\87"] = -30, ["\160\89"] = -55, ["va"] = -10, ["v,"] = -55, ["ve"] = -10, ["vo"] = -10, ["v."] = -70, ["w,"] = -55, ["wo"] = -10, ["w."] = -70, ["y,"] = -55, ["ye"] = -10, ["yo"] = -25, ["y."] = -70, } local WidthTimesI = { 250, 333, 420, 500, 500, 833, 778, 214, -- 32 - 39 333, 333, 500, 675, 250, 333, 250, 278, -- 40 - 47 500, 500, 500, 500, 500, 500, 500, 500, -- 48 - 55 500, 500, 333, 333, 675, 675, 675, 500, -- 56 - 63 920, 611, 611, 667, 722, 611, 611, 722, -- 64 - 71 722, 333, 444, 667, 556, 833, 667, 722, -- 72 - 79 611, 722, 611, 500, 556, 722, 611, 833, -- 80 - 87 611, 556, 556, 389, 278, 389, 422, 500, -- 88 - 95 333, 500, 500, 444, 500, 444, 278, 500, -- 96 - 103 500, 278, 278, 444, 278, 722, 500, 500, -- 104 - 111 500, 500, 389, 389, 278, 500, 444, 667, -- 112 - 119 444, 444, 389, 400, 275, 400, 541, 350, -- 120 - 127 500, 350, 333, 500, 556, 889, 500, 500, -- 128 - 135 333, 1000, 500, 333, 944, 350, 556, 350, -- 136 - 143 350, 333, 333, 556, 556, 350, 500, 889, -- 144 - 151 333, 980, 389, 333, 667, 350, 389, 556, -- 152 - 159 250, 389, 500, 500, 500, 500, 275, 500, -- 160 - 167 333, 760, 276, 500, 675, 675, 760, 333, -- 168 - 175 400, 675, 300, 300, 333, 500, 523, 250, -- 176 - 183 333, 300, 310, 500, 750, 750, 750, 500, -- 184 - 191 611, 611, 611, 611, 611, 611, 889, 667, -- 192 - 199 611, 611, 611, 611, 333, 333, 333, 333, -- 200 - 207 722, 667, 722, 722, 722, 722, 722, 675, -- 208 - 215 722, 722, 722, 722, 722, 556, 611, 500, -- 216 - 223 500, 500, 500, 500, 500, 500, 667, 444, -- 224 - 231 444, 444, 444, 444, 278, 278, 278, 278, -- 232 - 239 500, 500, 500, 500, 500, 500, 500, 675, -- 240 - 247 500, 500, 500, 500, 500, 444, 500, 444, -- 248 - 255 } local KernTimesI = { ["AC"] = -30, ["AG"] = -35, ["AO"] = -40, ["AQ"] = -40, ["AT"] = -37, ["AU"] = -50, ["AV"] = -105, ["AW"] = -95, ["AY"] = -55, ["A\146"] = -37, ["Au"] = -20, ["Av"] = -55, ["Aw"] = -55, ["Ay"] = -55, ["BA"] = -25, ["BU"] = -10, ["DA"] = -35, ["DV"] = -40, ["DW"] = -40, ["DY"] = -40, ["FA"] = -115, ["Fa"] = -75, ["F,"] = -135, ["Fe"] = -75, ["Fi"] = -45, ["Fo"] = -105, ["F."] = -135, ["Fr"] = -55, ["JA"] = -40, ["Ja"] = -35, ["J,"] = -25, ["Je"] = -25, ["Jo"] = -25, ["J."] = -25, ["Ju"] = -35, ["KO"] = -50, ["Ke"] = -35, ["Ko"] = -40, ["Ku"] = -40, ["Ky"] = -40, ["LT"] = -20, ["LV"] = -55, ["LW"] = -55, ["LY"] = -20, ["L\146"] = -37, ["Ly"] = -30, ["NA"] = -27, ["OA"] = -55, ["OT"] = -40, ["OV"] = -50, ["OW"] = -50, ["OX"] = -40, ["OY"] = -50, ["PA"] = -90, ["Pa"] = -80, ["P,"] = -135, ["Pe"] = -80, ["Po"] = -80, ["P."] = -135, ["QU"] = -10, ["RO"] = -40, ["RU"] = -40, ["RV"] = -18, ["RW"] = -18, ["RY"] = -18, ["TA"] = -50, ["TO"] = -18, ["Ta"] = -92, ["T:"] = -55, ["T,"] = -74, ["Te"] = -92, ["T-"] = -74, ["Ti"] = -55, ["To"] = -92, ["T."] = -74, ["Tr"] = -55, ["T;"] = -65, ["Tu"] = -55, ["Tw"] = -74, ["Ty"] = -74, ["UA"] = -40, ["U,"] = -25, ["U."] = -25, ["VA"] = -60, ["VO"] = -30, ["Va"] = -111, ["V:"] = -65, ["V,"] = -129, ["Ve"] = -111, ["V-"] = -55, ["Vi"] = -74, ["Vo"] = -111, ["V."] = -129, ["V;"] = -74, ["Vu"] = -74, ["WA"] = -60, ["WO"] = -25, ["Wa"] = -92, ["W:"] = -65, ["W,"] = -92, ["We"] = -92, ["W-"] = -37, ["Wi"] = -55, ["Wo"] = -92, ["W."] = -92, ["W;"] = -65, ["Wu"] = -55, ["Wy"] = -70, ["YA"] = -50, ["YO"] = -15, ["Ya"] = -92, ["Y:"] = -65, ["Y,"] = -92, ["Ye"] = -92, ["Y-"] = -74, ["Yi"] = -74, ["Yo"] = -92, ["Y."] = -92, ["Y;"] = -65, ["Yu"] = -92, ["ag"] = -10, ["b."] = -40, ["bu"] = -20, ["ch"] = -15, ["ck"] = -20, [",\148"] = -140, [",\146"] = -140, ["e,"] = -10, ["eg"] = -40, ["e."] = -15, ["ev"] = -15, ["ew"] = -15, ["ex"] = -20, ["ey"] = -30, ["f,"] = -10, ["ff"] = -18, ["fi"] = -20, ["f."] = -15, ["f\146"] = 92, ["g,"] = -10, ["ge"] = -10, ["gg"] = -10, ["g."] = -15, ["ke"] = -10, ["ko"] = -10, ["ky"] = -10, ["nv"] = -40, ["og"] = -10, ["ov"] = -10, [".\148"] = -140, [".\146"] = -140, ["\145\145"] = -111, ["\146\100"] = -25, ["\146\146"] = -111, ["\146\114"] = -25, ["\146\115"] = -40, ["\146\160"] = -111, ["\146\116"] = -30, ["\146\118"] = -10, ["ra"] = -15, ["rc"] = -37, ["r,"] = -111, ["rd"] = -37, ["re"] = -37, ["rg"] = -37, ["r-"] = -20, ["ro"] = -45, ["r."] = -111, ["rq"] = -37, ["rs"] = -10, ["\160\65"] = -18, ["\160\84"] = -18, ["\160\86"] = -35, ["\160\87"] = -40, ["\160\89"] = -75, ["v,"] = -74, ["v."] = -74, ["w,"] = -74, ["w."] = -74, ["y,"] = -55, ["y."] = -55, } local WidthTimesBI = { 250, 389, 555, 500, 500, 833, 778, 278, -- 32 - 39 333, 333, 500, 570, 250, 333, 250, 278, -- 40 - 47 500, 500, 500, 500, 500, 500, 500, 500, -- 48 - 55 500, 500, 333, 333, 570, 570, 570, 500, -- 56 - 63 832, 667, 667, 667, 722, 667, 667, 722, -- 64 - 71 778, 389, 500, 667, 611, 889, 722, 722, -- 72 - 79 611, 722, 667, 556, 611, 722, 667, 889, -- 80 - 87 667, 611, 611, 333, 278, 333, 570, 500, -- 88 - 95 333, 500, 500, 444, 500, 444, 333, 500, -- 96 - 103 556, 278, 278, 500, 278, 778, 556, 500, -- 104 - 111 500, 500, 389, 389, 278, 556, 444, 667, -- 112 - 119 500, 444, 389, 348, 220, 348, 570, 350, -- 120 - 127 500, 350, 333, 500, 500, 1000, 500, 500, -- 128 - 135 333, 1000, 556, 333, 944, 350, 611, 350, -- 136 - 143 350, 333, 333, 500, 500, 350, 500, 1000, -- 144 - 151 333, 1000, 389, 333, 722, 350, 389, 611, -- 152 - 159 250, 389, 500, 500, 500, 500, 220, 500, -- 160 - 167 333, 747, 266, 500, 606, 606, 747, 333, -- 168 - 175 400, 570, 300, 300, 333, 576, 500, 250, -- 176 - 183 333, 300, 300, 500, 750, 750, 750, 500, -- 184 - 191 667, 667, 667, 667, 667, 667, 944, 667, -- 192 - 199 667, 667, 667, 667, 389, 389, 389, 389, -- 200 - 207 722, 722, 722, 722, 722, 722, 722, 570, -- 208 - 215 722, 722, 722, 722, 722, 611, 611, 500, -- 216 - 223 500, 500, 500, 500, 500, 500, 722, 444, -- 224 - 231 444, 444, 444, 444, 278, 278, 278, 278, -- 232 - 239 500, 556, 500, 500, 500, 500, 500, 570, -- 240 - 247 500, 556, 556, 556, 556, 444, 500, 444, -- 248 - 255 } local KernTimesBI = { ["AC"] = -65, ["AG"] = -60, ["AO"] = -50, ["AQ"] = -55, ["AT"] = -55, ["AU"] = -50, ["AV"] = -95, ["AW"] = -100, ["AY"] = -70, ["A\146"] = -74, ["Au"] = -30, ["Av"] = -74, ["Aw"] = -74, ["Ay"] = -74, ["BA"] = -25, ["BU"] = -10, ["DA"] = -25, ["DV"] = -50, ["DW"] = -40, ["DY"] = -50, ["FA"] = -100, ["Fa"] = -95, ["F,"] = -129, ["Fe"] = -100, ["Fi"] = -40, ["Fo"] = -70, ["F."] = -129, ["Fr"] = -50, ["JA"] = -25, ["Ja"] = -40, ["J,"] = -10, ["Je"] = -40, ["Jo"] = -40, ["J."] = -10, ["Ju"] = -40, ["KO"] = -30, ["Ke"] = -25, ["Ko"] = -25, ["Ku"] = -20, ["Ky"] = -20, ["LT"] = -18, ["LV"] = -37, ["LW"] = -37, ["LY"] = -37, ["L\146"] = -55, ["Ly"] = -37, ["NA"] = -30, ["OA"] = -40, ["OT"] = -40, ["OV"] = -50, ["OW"] = -50, ["OX"] = -40, ["OY"] = -50, ["PA"] = -85, ["Pa"] = -40, ["P,"] = -129, ["Pe"] = -50, ["Po"] = -55, ["P."] = -129, ["QU"] = -10, ["RO"] = -40, ["RT"] = -30, ["RU"] = -40, ["RV"] = -18, ["RW"] = -18, ["RY"] = -18, ["TA"] = -55, ["TO"] = -18, ["Ta"] = -92, ["T:"] = -74, ["T,"] = -92, ["Te"] = -92, ["T-"] = -92, ["Ti"] = -37, ["To"] = -95, ["T."] = -92, ["Tr"] = -37, ["T;"] = -74, ["Tu"] = -37, ["Tw"] = -37, ["Ty"] = -37, ["UA"] = -45, ["VA"] = -85, ["VG"] = -10, ["VO"] = -30, ["Va"] = -111, ["V:"] = -74, ["V,"] = -129, ["Ve"] = -111, ["V-"] = -70, ["Vi"] = -55, ["Vo"] = -111, ["V."] = -129, ["V;"] = -74, ["Vu"] = -55, ["WA"] = -74, ["WO"] = -15, ["Wa"] = -85, ["W:"] = -55, ["W,"] = -74, ["We"] = -90, ["W-"] = -50, ["Wi"] = -37, ["Wo"] = -80, ["W."] = -74, ["W;"] = -55, ["Wu"] = -55, ["Wy"] = -55, ["YA"] = -74, ["YO"] = -25, ["Ya"] = -92, ["Y:"] = -92, ["Y,"] = -92, ["Ye"] = -111, ["Y-"] = -92, ["Yi"] = -55, ["Yo"] = -111, ["Y."] = -74, ["Y;"] = -92, ["Yu"] = -92, ["bb"] = -10, ["b."] = -40, ["bu"] = -20, ["ch"] = -10, ["ck"] = -10, [",\148"] = -95, [",\146"] = -95, ["eb"] = -10, ["f,"] = -10, ["fe"] = -10, ["ff"] = -18, ["fo"] = -10, ["f."] = -10, ["f\146"] = 55, ["ke"] = -30, ["ko"] = -10, ["nv"] = -40, ["ov"] = -15, ["ow"] = -25, ["ox"] = -10, ["oy"] = -10, [".\148"] = -95, [".\146"] = -95, ["\145\145"] = -74, ["\146\100"] = -15, ["\146\146"] = -74, ["\146\114"] = -15, ["\146\115"] = -74, ["\146\160"] = -74, ["\146\116"] = -37, ["\146\118"] = -15, ["r,"] = -65, ["r."] = -65, ["\160\65"] = -37, ["\160\86"] = -70, ["\160\87"] = -70, ["\160\89"] = -70, ["v,"] = -37, ["ve"] = -15, ["vo"] = -15, ["v."] = -37, ["wa"] = -10, ["w,"] = -37, ["we"] = -10, ["wo"] = -15, ["w."] = -37, ["xe"] = -10, ["y,"] = -37, ["y."] = -37, } local WidthList = { WidthHelvetica, WidthHelveticaB, WidthHelveticaO, WidthHelveticaBO, WidthTimes, WidthTimesB, WidthTimesI, WidthTimesBI, } local KernList = { KernHelvetica, KernHelveticaB, KernHelveticaO, KernHelveticaBO, KernTimes, KernTimesB, KernTimesI, KernTimesBI, } ----------------------------------------------------------------------- -- exporters:SaveToPDF -- -- Exports the document in the current window to a PDF format file. -- ----------------------------------------------------------------------- function exporters:SaveToPDF() local selBeg, selEnd = exportutil.GetSelPos() -- line numbering logic local NUMSPACING = tonumber(props["export.pdf.linenumspacing"]) or 2 if NUMSPACING < 0 or NUMSPACING > 99 then NUMSPACING = 2 end local NUMWIDTH = #tostring(editor.LineCount) local linenumbers = exportutil.propbool("export.pdf.linenumbers", 0) -- -- PDF Exporter. Status: Beta -- Contributed by Ahmad M. Zawawi -- Modifications by Darren Schroeder Feb 22, 2003; Philippe Lhoste 2003-10 -- Overhauled by Kein-Hong Man 2003-11 -- -- This exporter is meant to be small and simple; users are expected to -- use other methods for heavy-duty formatting. PDF elements marked with -- "PDF1.4Ref" states where in the PDF 1.4 Reference Spec (the PDF file of -- which is freely available from Adobe) the particular element can be found. -- -- Possible TODOs that will probably not be implemented: full styling, -- optimization, font substitution, compression, character set encoding. -- local PDF_TAB_DEFAULT = 8 local PDF_FONT_DEFAULT = 2 -- Helvetica local PDF_FONTSIZE_DEFAULT = 10 local PDF_SPACING_DEFAULT = 1.2 local PDF_HEIGHT_DEFAULT = 792 -- Letter local PDF_WIDTH_DEFAULT = 612 local PDF_MARGIN_DEFAULT = 72 -- 1.0" local PDF_ENCODING = "WinAnsiEncoding" local PDFfontNames = { "Courier", "Courier-Bold", "Courier-Oblique", "Courier-BoldOblique", "Helvetica", "Helvetica-Bold", "Helvetica-Oblique", "Helvetica-BoldOblique", "Times-Roman", "Times-Bold", "Times-Italic", "Times-BoldItalic", } -- ascender, descender aligns font origin point with page local PDFfontAscenders = { 629, 718, 699, } local PDFfontDescenders = { 157, 207, 217, } local CourierWidth = 600 -- easy lookup for space width local SpaceWidth = { 600, 278, 250, } -- This class conveniently handles the tracking of PDF objects -- so that the cross-reference table can be built (PDF1.4Ref(p39)) -- All writes to fp passes through a PDFObjectTracker object. -- PDFObjectTracker local oT = {} function oT:init(fp_) self.fp = fp_ self.offsetList = {} self.index = 1 end function oT:write(objectData) -- note binary write used, open with "wb" self.fp:write(objectData) end -- returns object number assigned to the supplied data function oT:add(objectData) -- save offset, then format and write object self.offsetList[self.index] = self.fp:seek() self:write(self.index) self:write(" 0 obj\n") self:write(objectData) self:write("endobj\n") self.index = self.index + 1 return self.index - 1 end -- builds xref table, returns file offset of xref table function oT:xref() -- xref start index and number of entries local xrefStart = self.fp:seek() self:write("xref\n0 ") self:write(self.index) -- a xref entry *must* be 20 bytes long (PDF1.4Ref(p64)) -- so extra space added; also the first entry is special self:write("\n0000000000 65535 f \n") for i = 1, self.index - 1 do local val = tostring(self.offsetList[i]) self:write(string.rep("0", 10 - #val)..val) self:write(" 00000 n \n") end return xrefStart end -- PDFRender local pr = {} -- Object to manage line and page rendering. Apart from startPDF, endPDF -- everything goes in via add() and nextLine() so that line formatting -- and pagination can be done properly. -- pr.style = {} pr.pageMargin = {} -- function pr:init() self.pageStarted = false self.pageCount = 0 end -- function pr:fontToPoints(thousandths) return self.fontSize * thousandths / 1000.0 end -- function pr:setStyle(oldStyle, style_) local styleNext = style_ if style_ == -1 then styleNext = self.styleCurrent end local buff = "" if styleNext ~= self.styleCurrent or style_ == -1 then if self.style[self.styleCurrent].font ~= self.style[styleNext].font or style_ == -1 then buff = string.format("/F%d %d Tf ", self.style[styleNext].font + 1, self.fontSize) end if self.style[self.styleCurrent].fore ~= self.style[styleNext].fore or style_ == -1 then buff = buff..self.style[styleNext].fore.."rg " end return buff end return oldStyle end -- function pr:lineNum(n) return string.rep(self.numspace, NUMWIDTH - #n)..n end -- function pr:startPDF() if self.fontSize <= 0 then self.fontSize = PDF_FONTSIZE_DEFAULT end -- leading is the term for distance between lines self.leading = self.fontSize * pr.spacing -- sanity check for page size and margins local pageWidthMin = math.floor(self.leading) + self.pageMargin.left + self.pageMargin.right if self.pageWidth < pageWidthMin then self.pageWidth = pageWidthMin end local pageHeightMin = math.floor(self.leading) + self.pageMargin.top + self.pageMargin.bottom if self.pageHeight < pageHeightMin then self.pageHeight = pageHeightMin end -- start to write PDF file here (PDF1.4Ref(p63)) -- ASCII>127 characters to indicate binary-possible stream oT:write("%PDF-1.3\n%Η쏒\n") self.styleCurrent = exportutil.STYLE_DEFAULT -- build objects for font resources; note that font objects are -- *expected* to start from index 1 since they are the first objects -- to be inserted (PDF1.4Ref(p317)) for i = 1,4 do oT:add(string.format("<>\n", i, PDFfontNames[self.fontSet * 4 + i - 4])) end self.pageContentStart = oT.index -- font index for wrapping self.fontListBase = (self.fontSet - 2) * 4 + 1 -- digit width -> space if self.fontSet == 1 then self.numspace = " " else self.numspace = " " end self.numindent = string.rep(self.numspace, NUMWIDTH).. string.rep(" ", NUMSPACING) self.numindentsz = #self.numindent * self:fontToPoints(SpaceWidth[self.fontSet]) end -- function pr:endPDF() if self.pageStarted then -- flush buffers self:endPage() end -- refer to all used or unused fonts for simplicity local resourceRef = oT:add("<> >>\n") -- create all the page objects (PDF1.4Ref(p88)) -- forward reference pages object; calculate its object number local pageObjectStart = oT.index local pagesRef = pageObjectStart + self.pageCount for i = 0, self.pageCount - 1 do oT:add(string.format("<>\n", pagesRef, self.pageWidth, self.pageHeight, self.pageContentStart + i, resourceRef)) end -- create page tree object (PDF1.4Ref(p86)) self.pageData = "<>\n", self.pageCount) oT:add(self.pageData) -- create catalog object (PDF1.4Ref(p83)) local catalogRef = oT:add(string.format("<>\n", pagesRef)) -- append the cross reference table (PDF1.4Ref(p64)) local xref = oT:xref() -- end the file with the trailer (PDF1.4Ref(p67)) oT:write(string.format("trailer\n<< /Size %d /Root %d 0 R\n>>".. "\nstartxref\n%d\n%%%%EOF\n", oT.index, catalogRef, xref)) end -- function pr:add(ch, style_) if not self.pageStarted then self:startPage() end -- perform pairwise kerning (PDF1.5Ref(p370) local kern = "" local kernvalue = 0 if self.kern then local kerntable = KernList[self.fontListBase + self.style[style_].font] kernvalue = kerntable[self.lastChar..ch] or 0 if kernvalue ~= 0 then kern = ")"..(-kernvalue).."(" end end -- full wrapping handling via table lookup if self.wrap then local glyphWidth if self.fontSet == 1 then -- for Courier (fixed), trivial glyphWidth = self:fontToPoints(CourierWidth) else -- for Helvetica & Times, trap control codes, or lookup -- proportional width from the selected font metric table -- WARNING tables are in WinAnsi order, not AFM order local CH = string.byte(ch) - 31 if CH >= 1 then local widthtable = WidthList[self.fontListBase + self.style[style_].font] glyphWidth = self:fontToPoints(widthtable[CH] + kernvalue) else -- not sure what to do with control codes glyphWidth = 0 end end self.xPos = self.xPos + glyphWidth -- if cannot fit into a line, flush, wrap to next line if self.xPos > self.pageWidth - self.pageMargin.right then kern = "" self:nextLine() if linenumbers then -- move left margin for line numbering self.xPos = self.xPos + self.numindentsz self.segment = self.numindent -- force style reset self.styleCurrent = style_ self.segStyle = self:setStyle(self.segStyle, -1) self.justWhiteSpace = false end self.xPos = self.xPos + glyphWidth end end -- if different style, then change to style if style_ ~= self.styleCurrent then self:flushSegment() -- output code (if needed) for new style self.segStyle = self:setStyle(self.segStyle, style_) self.stylePrev = self.styleCurrent self.styleCurrent = style_ end -- other processing and escape some characters if ch ~= " " then self.justWhiteSpace = false end self.lastChar = ch if ch == ")" or ch == "(" or ch == "\\" then ch = "\\"..ch end self.segment = self.segment..kern..ch -- add to segment data end -- function pr:flushSegment() if #self.segment > 0 then if self.justWhiteSpace then -- optimization possible because space widths are same for -- normal, bold and oblique combinations of Helvetica/Times self.styleCurrent = self.stylePrev else self.pageData = self.pageData..self.segStyle if self.kern then self.pageData = self.pageData.."[("..self.segment..")]TJ\n" else self.pageData = self.pageData.."("..self.segment..")Tj\n" end self.segment = "" end end self.segStyle = "" self.justWhiteSpace = true end -- function pr:startPage() self.pageStarted = true self.firstLine = true self.pageCount = self.pageCount + 1 local fontAscender = self:fontToPoints(PDFfontAscenders[self.fontSet]) self.yPos = self.pageHeight - self.pageMargin.top - fontAscender -- start a new page self.pageData = string.format("BT 1 0 0 1 %d %d Tm\n", self.pageMargin.left, math.floor(self.yPos)) -- force setting of initial font, colour self.segStyle = self:setStyle(self.segStyle, -1) self.pageData = self.pageData..self.segStyle self.xPos = self.pageMargin.left self.segment = "" self:flushSegment() self.lastChar = "" end -- function pr:endPage() self.pageStarted = false self:flushSegment() -- build actual text object; +3 is for "ET\n" -- PDF1.4Ref(p38) EOL marker preceding endstream not counted -- concatenate stream within the text object oT:add(string.format("<>\nstream\n%s".. "ET\nendstream\n", #self.pageData - 1 + 3, self.pageData)) end -- function pr:nextLine() if not self.pageStarted then self:startPage() end self.xPos = self.pageMargin.left self:flushSegment() -- PDF follows cartesian coords, subtract -> down self.yPos = self.yPos - self.leading local fontDescender = self:fontToPoints(PDFfontDescenders[self.fontSet]) if self.yPos < self.pageMargin.bottom + fontDescender then self:endPage() self:startPage() return end local buffer if self.firstLine then buffer = string.format("0 -%.1f TD\n", self.leading) self.firstLine = false else buffer = "T*\n" end self.pageData = self.pageData..buffer end editor:Colourise(0, -1) -- read exporter flags local tabSize = tonumber(props["tabsize"]) if not tabSize or tabSize <= 0 then tabSize = PDF_TAB_DEFAULT end -- read magnification value to add to default screen font size local propItem pr.fontSize = tonumber(props["export.pdf.magnification"]) or 0 -- set font family according to face name propItem = props["export.pdf.font"] pr.fontSet = PDF_FONT_DEFAULT; if propItem then if propItem == "Courier" then pr.fontSet = 1 elseif propItem == "Helvetica" then pr.fontSet = 2 elseif propItem == "Times" then pr.fontSet = 3 end end -- read line spacing value pr.spacing = tonumber(props["export.pdf.linespacing"]) or PDF_SPACING_DEFAULT if pr.spacing <= 0 or pr.spacing >= 10 then pr.spacing = PDF_SPACING_DEFAULT end -- wrap long lines flag pr.wrap = exportutil.propbool("export.pdf.wrap", 1) -- kerning flag pr.kern = exportutil.propbool("export.pdf.kerning", 0) if pr.fontSet == 1 then pr.kern = false -- Courier has no kerning end -- returns comma-separated fields in a property value as a list local function parseProp(prop) local propValue = props[prop] local propList = {} if not propValue or propValue == "" then return propList end for v in string.gfind(propValue, "([^,]+),?") do table.insert(propList, v) end return propList end -- page size: width, height propItem = parseProp("export.pdf.pagesize") pr.pageWidth = tonumber(propItem[1]) if not pr.pageWidth or pr.pageWidth < 0 then pr.pageWidth = PDF_WIDTH_DEFAULT end pr.pageHeight = tonumber(propItem[2]) if not pr.pageHeight or pr.pageHeight < 0 then pr.pageHeight = PDF_HEIGHT_DEFAULT end -- page margins: left, right, top, bottom propItem = parseProp("export.pdf.margins") pr.pageMargin.left = tonumber(propItem[1]) if not pr.pageMargin.left or pr.pageMargin.left < 0 then pr.pageMargin.left = PDF_MARGIN_DEFAULT end pr.pageMargin.right = tonumber(propItem[2]) if not pr.pageMargin.right or pr.pageMargin.right < 0 then pr.pageMargin.right = PDF_MARGIN_DEFAULT end pr.pageMargin.top = tonumber(propItem[3]) if not pr.pageMargin.top or pr.pageMargin.top < 0 then pr.pageMargin.top = PDF_MARGIN_DEFAULT end pr.pageMargin.bottom = tonumber(propItem[4]) if not pr.pageMargin.bottom or pr.pageMargin.bottom < 0 then pr.pageMargin.bottom = PDF_MARGIN_DEFAULT end -- collect all styles available for that 'language' -- or the default style if no language is available... stylemgr:setlexer(editor.Lexer) for i = 0, exportutil.STYLE_MAX do -- get keys prstyle = {} prstyle.font = 0 prstyle.fore = "" local sd = stylemgr:locate(i) if sd.specified ~= "" then if sd.italics then prstyle.font = prstyle.font + 2 end if sd.bold then prstyle.font = prstyle.font + 1 end if sd.fore then -- grab colour components (max string length produced = 18) local function colorElem(c) if c == 0 then return "0 " end -- optimise if c == 255 then return "1 " end -- 3 decimal places for enough dynamic range return string.format("%.3f ", c / 255) end prstyle.fore = colorElem(sd.fore.r).. colorElem(sd.fore.g).. colorElem(sd.fore.b) elseif i == exportutil.STYLE_DEFAULT then prstyle.fore = "0 0 0 " end -- grab font size from default style if i == exportutil.STYLE_DEFAULT then if sd.size > 0 then pr.fontSize = pr.fontSize + sd.size else pr.fontSize = PDF_FONTSIZE_DEFAULT end end end--if sd.specified pr.style[i] = prstyle end--for -- patch in default foregrounds for i = 0, exportutil.STYLE_MAX do if pr.style[i].fore == "" then pr.style[i].fore = pr.style[exportutil.STYLE_DEFAULT].fore end end local saveName = exportutil.exportfile(props["FileDir"], props["FileName"], "pdf") local fp = io.open(saveName, "wb") if not fp then error("exporters:SaveToPDF: could not save file \""..saveName.."\"") end if exportutil.VERBOSE ~= 0 then _ALERT("\nExporting to PDF, filepath: "..saveName) end -- initialise PDF rendering oT:init(fp) pr:init() pr:startPDF() -- do here all the writing -- local lengthDoc = editor.Length local lineIndex = 0 if selEnd == 0 then -- enable zero length docs pr:nextLine() else local i = selBeg while i < selEnd do local ch = exportutil.CharAt(i) local style = exportutil.StyleAt(i) if linenumbers and lineIndex == 0 then -- handle line numbering local ln = pr:lineNum(editor:LineFromPosition(i) + 1).. string.rep(" ", NUMSPACING) for j = 1, #ln do pr:add(string.sub(ln, j, j), exportutil.STYLE_DEFAULT) end end if ch == "\t" then -- expand tabs local ts = tabSize - lineIndex % tabSize lineIndex = lineIndex + ts for j = 1, ts do pr:add(" ", style) -- add ts count of spaces end elseif ch == "\r" or ch == "\n" then if ch == "\r" and exportutil.CharAt(i + 1) == "\n" then i = i + 1 end -- close and begin a newline... pr:nextLine() lineIndex = 0 else -- write the character normally... pr:add(ch, style) lineIndex = lineIndex + 1 end--ch i = i + 1 end--while end--if -- write required stuff and close the PDF file pr:endPDF() fp:close() if exportutil.VERBOSE ~= 0 then exportutil.progress("... done.") end end -- end of script