🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.postscript.programming
Article #127

Re: Auto-kerning

#127
From: jdaw1
Date: Mon, 17 Nov 2008 03:21
175 lines
6411 bytes
Thank you for your help. Much of my PostScript code handles that which
I call a compound string, this being any of:
-- A string;
-- The name of a glyph;
-- Any array of compound objects;
-- Code that does any of:
-- -- Leave on the stack ≥0 compound objects;
-- -- Move the currentpoint by a distance proportional to
CurrentFontSize (e.g., for kerning or superscripting);
-- -- Change the typeface (probably with selectfont), the size of the
new typeface being proportional to CurrentFontSize;
-- -- Change the current colour (usually with setgray or setrgbcolor);
-- -- Generate the path of a shape (without calling newpath or making
any changes to the clipping path), the shape's position being
determined by the currentpoint, and its size being proportional to
CurrentFontSize;
-- -- Optionally paint said shape with an unbinded call to any of
fill, eofill, stroke, ufill, ueofill, shfill.

Next define a KernTriples array to be an array, of length an integer
multiple of 3, resembling
[
/A /C -55
/A /Cacute -55
...
]
and set AdobeFontMetrics-TimesBold to the kerning data  above for
Times-Bold.

Then, with the definitions below and  and the kerning list in posts
above,
  [(Ch) /acircumflex (teau L) /eacute (oville-Barton)]
  dup == AdobeFontMetrics-TimesBold exch InsertKernCode ==
outputs
  [(Ch) /acircumflex (teau L) /eacute (oville-Barton)]
  [(Ch) /acircumflex (teau L) /eacute (o) {-10 CurrentFontSize mul
1000 div 0 rmoveto} (ville-Barton)]





% [KernTriples] CompoundString  InsertKernCode  NewCompoundString
/InsertKernCode
{
	1 dict begin
	/MostRecentGlyph /Null def
	1 InsertKernCodeRec
	end
} bind def  % InsertKernCode

% [KernTriples] CompoundString NoExecDepth  InsertKernCodeRec
NewCompoundString
/InsertKernCodeRec
{
	4 dict begin
	/NoExecDepth exch def
	/param exch def
	/KernTriples exch def

	% Glyph|Int Glyph|Int  KernAmount  Number
	/KernAmount
	{
		3 dict begin
		/Glyph1 exch def
		/Glyph0 exch def
		Glyph1 type /integertype eq {/Glyph1 ThisEncoding Glyph1 get def} if
		Glyph0 type /integertype eq {/Glyph0 ThisEncoding Glyph0 get def} if
		0
		0  3  KernTriples length 1 sub
		{
			/kt exch def
			Glyph0 KernTriples kt get eq
			{
				Glyph1 KernTriples kt 1 add get eq
				{
					pop
					KernTriples kt 2 add get
					exit
				} if  % Glyph1 KernTriples kt 1 add get eq
			} if  % Glyph0 KernTriples kt get eq
		} for  % KernTriples
		end
	} def  % KernAmount

	[ /param load  NoExecDepth  InsertKernCodeRecRec ]
	dup length 1 eq {0 get} if
	end
} def  % InsertKernCodeRec

/InsertKernCodeRecRec
{
	3 dict begin
	/NoExecDepth exch def
	/param exch def
	/ThisEncoding currentfont /Encoding get def  % redone here in case
code changes currentfont
	/param load xcheck
	{
		NoExecDepth 0 gt
		{
			{  1 dict begin /MostRecentGlyph /MostRecentGlyph def KernTriples  /
param  /NoExecDepth  InsertKernCodeRec end }
			%  0   1    2          3                4          5
6          7          8                9         10
			dup length array copy cvx
			dup  4  MostRecentGlyph  put
			dup  6  KernTriples  put
			dup  7  /param load  put  % replace /param with its current value,
a not-quite // operation
			dup  8  NoExecDepth 1 sub  put
		}
		{
			[ /param load execU ]  0  InsertKernCodeRecRec
		} ifelse  % NoExecDepth 0 gt
	}
	{
	param type /stringtype eq
	{
		MostRecentGlyph /Null ne
		{
			MostRecentGlyph  param 0 get  KernAmount
			dup 0 eq {pop}
			{
				{/KernAmount CurrentFontSize mul 1000 div 0 rmoveto}
				dup length array copy cvx
				dup  0  4 -1 roll  put
			} ifelse  % ... KernAmount ... 0 eq
		} if  % MostRecentGlyph /Null ne
		/ThisPieceStart 0 def
		0  1  param length 2 sub
		{
			/i exch def
			param i get  param i 1 add get  KernAmount
			dup 0 eq {pop}
			{
				{/KernAmount CurrentFontSize mul 1000 div 0 rmoveto}
				dup length array copy cvx
				dup  0  4 -1 roll  put
				param  ThisPieceStart  i ThisPieceStart sub 1 add  getinterval
exch
				/ThisPieceStart i 1 add def
			} ifelse  % ... KernAmount ... 0 eq
		} for
		param  ThisPieceStart  param length ThisPieceStart sub  getinterval
		/MostRecentGlyph ThisEncoding param dup length 1 sub get get store
	}
	{
	param type /nametype eq
	{
		MostRecentGlyph  param  KernAmount
		dup 0 eq {pop}
		{
			{/KernAmount CurrentFontSize mul 1000 div 0 rmoveto}
			dup length array copy cvx
			dup  0  4 -1 roll  put
		} ifelse  % ... KernAmount ... 0 eq
		/MostRecentGlyph param store
		param
	}
	{
	param type /arraytype eq
	{
		param {NoExecDepth  InsertKernCodeRecRec} forall
	}
	{
		(Error: InsertKernCodeRec parameter neither executable nor string
nor name nor array, being) OutputToLog
		/param load OutputToLog
	} ifelse  % /arraytype
	} ifelse  % /nametype
	} ifelse  % /stringtype
	} ifelse  % xcheck
	end
} bind def  % InsertKernCodeRecRec
Technical Details
Message-ID: <13cad4b2-c285-4d1d-acda-ba632603fbaa@a17g2000prm.googlegroups.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!a17g2000prm.googlegroups.com!not-for-mail
References: <32846ea9-dbe5-46b5-9f01-efaae5c1998e@a26g2000prf.googlegroups.com> <GGXSk.6409$x%.1907@nlpi070.nbdc.sbc.com> <84895d69-712d-4b7d-ad09-58c9858909ea@d10g2000pra.googlegroups.com> <5D5Tk.10513$Ws1.8102@nlpi064.nbdc.sbc.com> <1112e4f5-c7b3-4916-b09a-3a3279dc1156@k1g2000prb.googlegroups.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10c61a,c44b798dae02ef90
X-Google-Attributes: gid10c61a,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII
Path: arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!a17g2000prm.googlegroups.com!not-for-mail
From: jdaw1 <jdawiseman@gmail.com>
Newsgroups: adobe.postscript.programming
Subject: Re: Auto-kerning
Date: Sun, 16 Nov 2008 19:21:04 -0800 (PST)
Organization: http://groups.google.com
Lines: 175
Message-ID: <13cad4b2-c285-4d1d-acda-ba632603fbaa@a17g2000prm.googlegroups.com>
References: <32846ea9-dbe5-46b5-9f01-efaae5c1998e@a26g2000prf.googlegroups.com> 
 <GGXSk.6409$x%.1907@nlpi070.nbdc.sbc.com> <84895d69-712d-4b7d-ad09-58c9858909ea@d10g2000pra.googlegroups.com>
 <5D5Tk.10513$Ws1.8102@nlpi064.nbdc.sbc.com> <1112e4f5-c7b3-4916-b09a-3a3279dc1156@k1g2000prb.googlegroups.com>
NNTP-Posting-Host: 96.246.63.187
Mime-Version: 1.0
Content-Type: text/plain; charset=KOI8-R
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1226892065 31149 127.0.0.1 (17 Nov 2008 03:21:05 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Mon, 17 Nov 2008 03:21:05 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: a17g2000prm.googlegroups.com; posting-host=96.246.63.187; 
 posting-account=Cp97SgoAAAC0t1Gya5PaPqyoafMoOtAn
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10.5; en-US; 
 rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4,gzip(gfe),gzip(gfe)