Re: [ft] putting text in a box

2010-01-21 Thread Werner LEMBERG
 As I told you earlier: A negative bbox value descends below the
 baseline (which has y=0).

 How could a bounding box represent both the overall size of the
 glyph and the descent at the same time?

Sorry for being imprecise.  A bbox consists of four values: The (x,y)
values of the lower left (llx,lly) and the upper right (urx,ury)
corner.  A box of a glyph with a descender looks like this:


   (urx,ury)
   +--+
   |  |
   |  |
   |  |
   |  |
 --+--+--  baseline (y = 0)
   |  |
   +--+
  (llx,lly)


If I say `a negative bbox value' I've meant that lly  0; the
descender is thus simply the value of lly.

 [...] let's say its height overall is 10 pixels (which completely
 encloses top-to-bottom the glyph) and the descent is 3 pixels.  How
 can both pieces of information be communicated through a box height?

Then you should have lly = -3 and ury = 7.

Hmm, I see that the description of FT_BBox doesn't mention the term
`baseline'.  I've improved it now hopefully by adding this:

  /* Note*/
  /*The bounding box is specified with the coordinates of the lower*/
  /*left and the upper right corner.  In PostScript, those values are  */
  /*often called (llx,lly) and (urx,ury), respectively.*/
  /*   */
  /*If `yMin' is negative, this value gives the glyph's descender. */
  /*Otherwise, the glyph doesn't descend below the baseline.   */
  /*Similarly, if `ymax' is positive, this value gives the glyph's */
  /*ascender.  */


Werner


___
Freetype mailing list
Freetype@nongnu.org
http://lists.nongnu.org/mailman/listinfo/freetype


RE: [ft] putting text in a box

2010-01-21 Thread David Bevan

Werner, 

Is it also worth stating what a negative llx (xMin) value means, to facilitate 
understanding.

David %^



 -Original Message-
 From: freetype-bounces+dbevan=emtex@nongnu.org [mailto:freetype-
 bounces+dbevan=emtex@nongnu.org] On Behalf Of Werner LEMBERG
 Sent: 21 January 2010 07:42
 To: d...@kinematics.com
 Cc: freetype@nongnu.org
 Subject: Re: [ft] putting text in a box
 
  As I told you earlier: A negative bbox value descends below the
  baseline (which has y=0).
 
  How could a bounding box represent both the overall size of the
  glyph and the descent at the same time?
 
 Sorry for being imprecise.  A bbox consists of four values: The (x,y)
 values of the lower left (llx,lly) and the upper right (urx,ury)
 corner.  A box of a glyph with a descender looks like this:
 
 
(urx,ury)
+--+
|  |
|  |
|  |
|  |
  --+--+--  baseline (y = 0)
|  |
+--+
   (llx,lly)
 
 
 If I say `a negative bbox value' I've meant that lly  0; the
 descender is thus simply the value of lly.
 
  [...] let's say its height overall is 10 pixels (which completely
  encloses top-to-bottom the glyph) and the descent is 3 pixels.  How
  can both pieces of information be communicated through a box height?
 
 Then you should have lly = -3 and ury = 7.
 
 Hmm, I see that the description of FT_BBox doesn't mention the term
 `baseline'.  I've improved it now hopefully by adding this:
 
   /* Note
 */
   /*The bounding box is specified with the coordinates of the lower
 */
   /*left and the upper right corner.  In PostScript, those values are
 */
   /*often called (llx,lly) and (urx,ury), respectively.
 */
   /*
 */
   /*If `yMin' is negative, this value gives the glyph's descender.
 */
   /*Otherwise, the glyph doesn't descend below the baseline.
 */
   /*Similarly, if `ymax' is positive, this value gives the glyph's
 */
   /*ascender.
 */
 
 
 Werner
 
 
 ___
 Freetype mailing list
 Freetype@nongnu.org
 http://lists.nongnu.org/mailman/listinfo/freetype



___
Freetype mailing list
Freetype@nongnu.org
http://lists.nongnu.org/mailman/listinfo/freetype


Re: [ft] putting text in a box

2010-01-21 Thread Dave Calkins
For reference, a good link is also the below, scroll to the bottom which 
talks about positioning glyphs on a bitmap of specified size and it also 
mentions subtracting the lower left corner of the bounding box from the 
pen pos to get the actual glyph aligned with the box.


http://freetype.sourceforge.net/freetype2/docs/glyphs/glyphs-7.html

On 1/21/2010 10:12 AM, Dave Calkins wrote:
Thanks a ton for the help!  Sure enough, my code was considering the 
overall size from the bbox (upper right - lower left) but I hadn't 
considered the fact that a negative lower left point was exactly the 
information I needed :)  Live and learn!


I'm able to now subtract the lower left x and y from my pen position 
and the result is the text itself is flush against the desired 
position.



On 1/21/2010 2:42 AM, Werner LEMBERG wrote:

As I told you earlier: A negative bbox value descends below the
baseline (which has y=0).

How could a bounding box represent both the overall size of the
glyph and the descent at the same time?

Sorry for being imprecise.  A bbox consists of four values: The (x,y)
values of the lower left (llx,lly) and the upper right (urx,ury)
corner.  A box of a glyph with a descender looks like this:


(urx,ury)
+--+
|  |
|  |
|  |
|  |
  --+--+--  baseline (y = 0)
|  |
+--+
   (llx,lly)


If I say `a negative bbox value' I've meant that lly  0; the
descender is thus simply the value of lly.




___
Freetype mailing list
Freetype@nongnu.org
http://lists.nongnu.org/mailman/listinfo/freetype





___
Freetype mailing list
Freetype@nongnu.org
http://lists.nongnu.org/mailman/listinfo/freetype


Re: [ft] putting text in a box

2010-01-20 Thread Dave Calkins


   

It seems like the bounding box calculation is always correct.  The
problem is that the descender I'm querying is for the font face in
general which I assume accounts for every glyph in the font.
 

If you have a negative value in the bbox, this is the amount below the
baseline.

   
I'm not getting negative values in the bounding box.  I'm getting a 
positive overall width and height for the text string in question 
(although I should say I'm calling the FreeTypeGL bounding box method, 
so I suppose I need to see which FreeType calls thats using).  And I can 
verify that this bounding box is correct.  If I render and check the 
bounding box, I can, in MSPaint for example, line it up with a box that 
size and it does exactly enclose all the text.  So the bounding box 
looks great.


The problem is that I need to know where to render the text.  When I set 
the output position, this positions the baseline of the text.  So the 
only way to put the text exactly in that box (I think) is to know the 
descender values for the individual chars in the specific string I'm 
rendering.


I can get a descender value for the font face overall, but this ends up 
being too large (for some fonts) and if I use this to position the 
string the string is too high since the specific string doesn't actually 
have descender values that large.




Any suggestions on computing the descenders for individual glyphs?
 

Calculate the bbox for individual glyphs.  In most cases, a cbox
should be sufficient, BTW.

   
I'll look again today, but I don't recall seeing a descender value for a 
glyph.  The example code I looked at computed a bounding box, telling me 
what box would enclose the char, but I need the distance the char 
extends below the baseline.  I could just have overlooked something though.

I took a look at the glyph metrics from FreeType, but these didn't
seem to help.  For example, I found a case where E seemed to
report a descender (comparing height and vertBearingY).
 

It's easily possible that the glyph `E' descends slightly (due to
serifs, for example).

   
In that case, the descent was definitely not from a serif.  It was a 
value much larger than you'd expect.  I drew the E, then drew a 
cross-hair at the output positionn and there was really no descent.




___
Freetype mailing list
Freetype@nongnu.org
http://lists.nongnu.org/mailman/listinfo/freetype


Re: [ft] putting text in a box

2010-01-20 Thread Dave Calkins
Thanks, I'll try both of those.  Do you know, though, of a way to get 
the descent value for an individual glyph reliably for any font?


On 1/20/2010 9:51 AM, Werner LEMBERG wrote:

If you have a negative value in the bbox, this is the amount below
the baseline.

   

I'm not getting negative values in the bounding box.
 

Hmm.  You should indeed write a small FreeType test program which
uses the FreeType API directly.  Then you can compare the results.

   

It's easily possible that the glyph `E' descends slightly (due to
serifs, for example).
   

In that case, the descent was definitely not from a serif.  It was a
value much larger than you'd expect.  I drew the E, then drew a
cross-hair at the output positionn and there was really no descent.
 

Which font?  You might use, say, FontForge to check the glyph's
dimensions.


 Werner


   



___
Freetype mailing list
Freetype@nongnu.org
http://lists.nongnu.org/mailman/listinfo/freetype


Re: [ft] putting text in a box

2010-01-20 Thread Werner LEMBERG

 Do you know, though, of a way to get the descent value for an
 individual glyph reliably for any font?

Normally, computing the cbox (or the bbox, to be absolutely sure for
the weird cases which shouldn't happen with well designed fonts)
should do the right thing.


Werner


___
Freetype mailing list
Freetype@nongnu.org
http://lists.nongnu.org/mailman/listinfo/freetype


Re: [ft] putting text in a box

2010-01-20 Thread dave

 Do you know, though, of a way to get the descent value for an
 individual glyph reliably for any font?

 Normally, computing the cbox (or the bbox, to be absolutely sure for
 the weird cases which shouldn't happen with well designed fonts)
 should do the right thing.


I guess this is what's confusing me.  I looked at the tutorial code for
getting the cbox, for example, and the result of the call is just that, a
box.  So that would be a box which completely enclosed the glyph right? 
How does that yield the information I need, namely the distance below the
baseline which the glyph extends?

If I have a box which encloses the glyph, then I could use that
information to figure out how much space I need.  However, when I render
the text at position X, Y that position sets the baseline of the text.  So
I'm still stuck figuring out how far below that baseline my glyphs will
go.  Without knowing that, I can't put text into a box.



___
Freetype mailing list
Freetype@nongnu.org
http://lists.nongnu.org/mailman/listinfo/freetype


Re: [ft] putting text in a box

2010-01-20 Thread Werner LEMBERG
 Do you know, though, of a way to get the descent value for an
 individual glyph reliably for any font?

 Normally, computing the cbox (or the bbox, to be absolutely sure
 for the weird cases which shouldn't happen with well designed
 fonts) should do the right thing.
 
 I guess this is what's confusing me.  I looked at the tutorial code
 for getting the cbox, for example, and the result of the call is
 just that, a box.  So that would be a box which completely enclosed
 the glyph right?

Yes.

 How does that yield the information I need, namely the distance
 below the baseline which the glyph extends?

As I told you earlier: A negative bbox value descends below the
baseline (which has y=0).  I have no idea what's going on with GL.
There might be even a bug in FreeType, thus my request to test it with
native FreeType API calls.

A possible reason for GL to disallow negative bbox values is the
PostScript rendering model which by default cuts off all coordinates
with non-positive values (since they are drawn outside of the `drawing
paper' with its physical origin (0,0) at the lower left corner).


Werner


___
Freetype mailing list
Freetype@nongnu.org
http://lists.nongnu.org/mailman/listinfo/freetype


Re: [ft] putting text in a box

2010-01-20 Thread dave
 I guess this is what's confusing me.  I looked at the tutorial code
 for getting the cbox, for example, and the result of the call is
 just that, a box.  So that would be a box which completely enclosed
 the glyph right?

 Yes.

 How does that yield the information I need, namely the distance
 below the baseline which the glyph extends?

 As I told you earlier: A negative bbox value descends below the
 baseline (which has y=0).

How could a bounding box represent both the overall size of the glyph and
the descent at the same time?  For example, consider a lower case y.  A
single value wouldn't be able to communicate both the overall height of
that glyph and the descent distance below the baseline would it?  In that
case let's say its height overall is 10 pixels (which completely encloses
top-to-bottom the glyph) and the decent is 3 pixels.  How can both pieces
of information be communicated through a box height?

 I have no idea what's going on with GL.
 There might be even a bug in FreeType, thus my request to test it with
 native FreeType API calls.

 A possible reason for GL to disallow negative bbox values is the
 PostScript rendering model which by default cuts off all coordinates
 with non-positive values (since they are drawn outside of the `drawing
 paper' with its physical origin (0,0) at the lower left corner).


Even ignoring the rendering piece of it for now, I'm just confused with
the metrics I guess.  If I have a glyph, lowercase y for example which
descends below the baseline, I know I can determine the bounding box for
it, but I also need another piece of information.  I need the distance
from the baseline to the bottom of the glyph, which I think will be less
than the bounding box size.

As far as GL, when you render it with GL at a given X,Y coordinate, for
example, the baseline of the text goes at that X,Y coordinate.  So if you
want the text string to be flush with a horizontal line, you have to know
how far each glyph in the string goes below the baseline so you can shift
it up by that amount.  Shifting it up by the largest descent in the string
would then have the string just touching the horizontal line.

I've been able to reliably (so far) get the bounding box, which tells me
the overall size of the text, but I can't seem to figure out how to get
those descent values for individual glyphs.  They would be smaller than
the heights of the bounding boxes so I'm thinking there must be another
value somewhere.



___
Freetype mailing list
Freetype@nongnu.org
http://lists.nongnu.org/mailman/listinfo/freetype