POV-Ray : Newsgroups : povray.text.scene-files : recreate kerning of ttf with 3.5 Server Time
23 Dec 2024 02:52:02 EST (-0500)
  recreate kerning of ttf with 3.5 (Message 1 to 3 of 3)  
From:
Subject: recreate kerning of ttf with 3.5
Date: 15 Feb 2002 09:29:34
Message: <sa6q6u8ic6tt2ntql1kt4mm2fiebtf1pih@4ax.com>
Thinking about problem posted by Hershel Robinson at
http://news.povray.org/3c6bb80e%40news.povray.org
I found that splitting text into letters and recreating it along anything is
difficoult becouse of kerning used with ttfs. Even in standard distribution of
3.5 (or rather current beta) there is a macro which wrongly handle this
problem. The problem is kerning and overlapped areas of letters. It is
possible that some letter finishes after one, two or even more letters.
Here is my solution (probably not final). Below script contains two public
macros and one private.

Macro vletter() calculates position of specified letter. It considers font,
string and offset of text. Meaning of this parameters is the same as in SDL
for text{}. Thickness is not considered becouse it not ifnfluences lower
corner of letter. Last parameter - position - gives number of calculated
letter. Macro vletter() return vector. When you use offset 0 then x coordinate
from result is position along curve - use it to placing text along curves.

Macro text_ttf() gives the same appearance as text{} statement. The only
difference is that is splits text{} object into separated letters. All
parameters are the same as for text{} statement except ttf signature at
begining. Originally I have created this macro to check if splitting text into
letters can speed up rendering of text. The answer is: it not influences
somehow. Rendering is sometimes one second faster, sometimes one second
slower. Probably it depends on current work of CPU.

Macro kernel() is provate tool for both above macros. It's engine. My English
limits explaining skills but if there is anybody interested how it works then
ask.

I used font Adine+Kirnberg to test this stuff. You can download this from
http://www.fontguy.com/font.asp?search=Adine+Kirnberg
Design of some letters has bugs but it's no a problem in testing.

Any comments ?

ABX

// START

#version 3.5;
light_source{-4+9*y 1}
camera{}

#declare A=array[14]{
"You know you have been raytracing too long when... "
"   ... You actually read all the documentation that comes with programs."
"   ... You have gone full circle and find your self writing a scene that contains"
"         only a shiny sphere hovering over a green and yellow checkered plane."
"   ... Your friends are used to the fact that you will suddenly stop walking"
"         in order to look at objects and figure out how to do them as CSGs."
"   ... You think that the evolution theory was based on the triangular origin of the
wheel."
"   ... You find yourself wishing you'd paid attention in math class to all those
formulae"
"         you thought you'd never have any use for in real life."
"   ... You take a photo course just to learn how to get the lighting right."
"   ... You wear fuzzy clothing to soften your shadow."
"   ... You want to cheat and look at nature's source code."
"   ... You've been asked how you did that thing you did,"
"       by the author of the raytracer you used to do it."
};

#macro kerning(Font,String,Thickness,Offset,Position)
  #local Support=" Additional text to adjust kerning at begining and end of
String...";
  #local HelpText=text{ttf Font concat(Support,String,Support) Thickness 0};
  #local Text=text{ttf Font substr(String,1,1) Thickness 0};
  #local N=strlen(String);
  #local n=1;
  #while(n<N)
    #local After=text{ttf Font concat(substr(String,n+1,strlen(String)-n),Support)
Thickness 0};
    #local Before=text{ttf Font concat(Support,substr(String,1,n)) Thickness 0};
    #local
Location=(max_extent(Text)+max_extent(HelpText)-max_extent(After)-max_extent(Before))*x+Offset;
    #local Text=union{
      object{Text}
      text{ttf Font substr(String,n+1,1) Thickness 0 translate Location}
    };
    #local n=n+1;
    #if(Position=n)
      #local Text=Location;
      #local n=N;
    #end
  #end
  Text
#end

#macro text_ttf(Font,String,Thickness,Offset)
  kerning(Font,String,Thickness,Offset,0)
#end

#macro vletter(Font,String,Offset,Position)
  #if((Position>strlen(String))|(Position<1)|(int(Position)!=Position))
    #error "Wrong value for Position parameter"
  #end
  #if(Position=1)
    #local Result=(0*x);
  #else
    #local Result=kerning(Font,String,0,Offset,Position);
  #end
  (Result+0)
#end

#local N=dimension_size(A,1);
#while(N)
  #local N=N-1;
  object{
    //text{ttf "Adks____.ttf" A[N] 0 0}
    text_ttf("Adks____.ttf" A[N] 0 0)
    translate <-10,7-N,17>
    pigment{color rgb 1}
  }
#end

// END


Post a reply to this message

From: Ron Parker
Subject: Re: recreate kerning of ttf with 3.5
Date: 15 Feb 2002 09:32:05
Message: <slrna6q6v6.30q.ron.parker@fwi.com>

> begining. Originally I have created this macro to check if splitting text into
> letters can speed up rendering of text. The answer is: it not influences
> somehow. Rendering is sometimes one second faster, sometimes one second
> slower. Probably it depends on current work of CPU.

This is probably because a text string is broken into individual letters 
already by the parser.

-- 
plane{-z,-3normal{crackle scale.2#local a=5;#while(a)warp{repeat x flip x}rotate
z*60#local a=a-1;#end translate-9*x}pigment{rgb 1}}light_source{-9red 1rotate 60
*z}light_source{-9rgb y rotate-z*60}light_source{9-z*18rgb z}text{ttf"arial.ttf"
"RP".01,0translate-<.6,.4,.02>pigment{bozo}}light_source{-z*3rgb-.2}//Ron Parker


Post a reply to this message

From:
Subject: Re: recreate kerning of ttf with 3.5
Date: 15 Feb 2002 09:50:41
Message: <om7q6uojhp3i8qt6vgdk5h0495vfmabpaa@4ax.com>
On 15 Feb 2002 09:32:05 -0500, Ron Parker <ron### [at] povrayorg> wrote:
> This is probably because a text string is broken into individual letters 
> already by the parser.

I supposed this kind of optimization but was too lazy to check it inside
ttf.c) Now I see description of ProcessNewTTF.

ABX


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.