addxchar

Upload: flavio-dos-santos

Post on 07-Apr-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/4/2019 addxchar

    1/6

    % Copyright (C) 1999 Aladdin Enterprises. All rights reserved.%% This software is provided AS-IS with no warranty, either express or% implied.%% This software is distributed under license and may not be copied,% modified or distributed except as expressly authorized under the terms

    % of the license contained in the file LICENSE in this distribution.%% For more information about licensing, please refer to% http://www.ghostscript.com/licensing/. For information on% commercial licensing, go to http://www.artifex.com/licensing/ or% contact Artifex Software, Inc., 101 Lucas Valley Road #110,% San Rafael, CA 94903, U.S.A., +1(415)492-9861.

    % $Id: addxchar.ps 6300 2005-12-28 19:56:24Z giles $% Add the Central European and other Adobe extended Latin characters to a% Type 1 font.% Requires -dWRITESYSTEMDICT to disable access protection.

    (type1ops.ps) runlibfile

    % ---------------- Utilities ---------------- %

    /addce_dict 50 dict defaddce_dict begin

    % Define the added copyright notice./addednotice (. Portions Copyright (C) 1999 Aladdin Enterprises.) def

    % Open a font for modification by removing the FID and changing the% FontName. Removing UniqueID and XUID is not necessary, since we

    % will only be adding characters./openfont { % openfont

  • 8/4/2019 addxchar

    2/6

    SBW 1 index .knownget {exch pop

    } {dup glyphcs { dup /hsbw eq { pop exit } if } forall2 array astoreSBW 3 -1 roll 2 index put

    } ifelse aload pop

    } def

    % Get the CharString for a glyph, as an array./glyphcs { % glyphcs CharStrings exch get4330 exch dup length string .type1decrypt exch popdup length lenIV sub lenIV exch getinterval0 () /SubFileDecode filter [ exch charstack_read ]

    } def

    % Find an occurrence of a value in an array./asearch { % asearch true

    % asearch falsefalse 0 4 2 roll exch {% Stack: false index value element

    2 copy eq { pop pop exch not exch dup exit } ifexch 1 add exch

    } forall pop pop} def

    % Convert an array back to a CharString./csdef { % csdef -charproc_string4330 exch dup .type1encrypt exch pop readonlyCharStrings 3 1 roll put

    } def

    % Split an accented character name./splitaccented { % splitaccented

    dup =string cvsdup 0 1 getinterval cvnexch dup length 1 sub 1 exch getinterval cvn

    } def

    % Begin the definition of a 'seac' character.% Defines accent, base, abox, bbox.% The initial dx lines up the origins of the base and the accent./beginseac { % beginseac

    % -mark- /hsbw /accent exch def /base exch def/abox [accent glyphbbox] def/bbox [base glyphbbox] def[ base glyphsbw /hsbw accent glyphsbw popdup 4 index sub

    } def

    % Center the accent over the base of a 'seac' character./centeraccent { % centeraccent bbox 2 get bbox 0 get add 2 divabox 2 get abox 0 get add 2 div

    sub add} def

  • 8/4/2019 addxchar

    3/6

    % Finish the definition of a 'seac' character./finishseac { % -mark- ... finishseac -exch cvi exch cvicharindex base get charindex accent get /seac ] csdef

    } def

    % ---------------- Main program ---------------- %

    % Define accented characters that can be made with seac,% with the accent centered over the character./seacchars [/Abreve /Amacron/Cacute /Ccaron /Dcaron/Ecaron /Edotaccent /Emacron/Gbreve/Idotaccent /Imacron/Lacute/Nacute /Ncaron/Ohungarumlaut /Omacron

    /Racute /Rcaron/Sacute /Scedilla/Tcaron/Uhungarumlaut /Umacron /Uogonek /Uring/Zacute /Zdotaccent/abreve /amacron/cacute /ccaron/ecaron /edotaccent /emacron/gbreve/lacute/nacute /ncaron/ohungarumlaut /omacron/racute /rcaron

    /sacute /scedilla/uhungarumlaut /umacron /uring/zacute /zdotaccent

    ] def

    % Define seac characters where the accent lines up with the right% edge of the character./seacrightchars [/Aogonek /Eogonek /Iogonek /aogonek /eogonek /iogonek /uogonek

    ] def

    % Define seac characters where the caron becomes an appended quoteright./seaccaronchars [/dcaron /lcaron /tcaron

    ] def

    % Define seac characters using commaaccent./seaccommachars [/Gcommaaccent /Kcommaaccent /Lcommaaccent /Ncommaaccent /Rcommaaccent/Scommaaccent /Tcommaaccent/gcommaaccent /kcommaaccent /lcommaaccent /ncommaaccent /rcommaaccent/scommaaccent /tcommaaccent

    ] def

    % Define the characters copied from the Symbol font.

    /symbolchars [/Delta /greaterequal /lessequal /lozenge /notequal /partialdiff/summation

  • 8/4/2019 addxchar

    4/6

    ] def

    % Define the procedures for editing the commaaccent character.% Delete all the hints, since it's too hard to adjust them./caedit mark/rmoveto { exch commatop sub cvi exch }/hstem { pop pop pop }

    /vstem 1 index/callothersubr {dup 3 eq { 4 { pop } repeat /skip true def } if

    }/pop { skip { pop /skip false def } if }

    .dicttomark def

    /addce { % addce

  • 8/4/2019 addxchar

    5/6

    % Adjust the X position if italic.dup italfactor mul 3 -1 roll add exch

    } {pop 0

    } ifelse} {pop 0

    } ifelsefinishseac

    } forall

    seacrightchars {splitaccented beginseacbbox 2 get abox 2 get sub add % line up right edges0 finishseac

    } forall

    /dcroat /d /hyphen beginseacbbox 2 get abox 2 get sub add % line up right edges

    0 finishseac

    /imacron /dotlessi /macron beginseaccenteraccent

    0 finishseac

    /Lcaron /L /quoteright beginseacbbox 2 get abox 2 get sub add % line up right edges

    0 finishseac

    seaccaronchars {dup =string cvs 0 1 getinterval cvn /quoteright beginseac

    % Move the quote to the right of the character.

    bbox 2 get abox 0 get sub 50 add add% Adjust the character width as well.

    4 -1 roll abox 2 get abox 0 get sub 50 add add cvi 4 1 roll0 finishseac

    } forall

    seaccommachars {dup =string cvs 0 1 getinterval cvn /comma beginseaccenteraccentcommatop neg

    % Lower the accent if the character extends below% the baseline

    bbox 1 get 0 .min addfinishseac

    } forall

    % Add the characters from the Symbol font.% We should scale them to match the FontBBox, but we don't.

    symbolchars {symbolfont /CharStrings get 1 index getCharStrings 3 1 roll put

    } forall

    % Add the one remaining character.

    CharStrings /Dcroat CharStrings /Eth get put

  • 8/4/2019 addxchar

    6/6

    % Recompute the FontBBox, since some of the accented characters% may have enlarged it.

    /llx 1000 def /lly 1000 def /urx 0 def /ury 0 defCharStrings {pop glyphbboxury .max /ury exch def urx .max /urx exch def

    lly .min /lly exch def llx .min /llx exch def} forall/FontBBox llx cvi lly cvi urx ceiling cvi ury ceiling cvi 4 packedarray def

    % Restore the Encoding and wrap up.

    [/Copyright /Notice] {FontInfo 1 index .knownget {addednotice concatstrings FontInfo 3 1 roll put

    } {pop

    } ifelse

    } forallFontName font openfontdup /Encoding origfont /Encoding get putdefinefont

    end end} def

    currentdict end readonly pop % addce_dict

    /addce { addce_dict begin addce end } def

    % ---------------- Integration ---------------- %

    % We would like to patch the font loader so that it adds the extended% Latin characters automatically. We haven't done this yet.

    % ---------------- Test program ---------------- %

    /TEST where { pop TEST } { false } ifelse {/FONT where { pop } { /FONT /Palatino-Italic def } ifelse(unprot.ps) runlibfileunprot(wrfont.ps) runlibfilewrfont_dict begin/eexec_encrypt true def/binary_CharStrings true def

    endsaveFONT findfont/Latin-CE exch addce setfont(t.ce.pfb) (w) file dup writefont closefile

    restore(prfont.ps) runlibfile(t.ce.pfb) (r) file .loadfont/Latin-CE DoFontquit

    } if