Giter VIP home page Giter VIP logo

Comments (16)

GoogleCodeExporter avatar GoogleCodeExporter commented on June 15, 2024
It looks to me like DrawString in freetype.go needs to be factored out into 
drawOrMeasureString(string, point, measure bool), which checks if measure == 
true and skips the drawing. Then there would be two public entry points, 
DrawString and MeasureString (same args, same return).

Tell me if you want me to submit a patch doing this.

Original comment by [email protected] on 7 Jun 2012 at 12:34

from freetype-go.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 15, 2024
A patch that implements what I mentioned is attached. See if it solves your 
problem.

Original comment by [email protected] on 7 Jun 2012 at 1:38

Attachments:

from freetype-go.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 15, 2024
Ah nice. I haven't tested it quite yet, but I understand what you did. Thanks!

So, the only caveat that remains is: how does one make sure the 'y' returned 
from MeasureString covers the bounding box of the text? (As of right now, the 
'y' seems to correspond to the base line of the text, so that if it's used as 
the Point.Max.Y for a bounding box, the box will cut off all letters that sink 
below that base line. Like the tail in 'y' or 'j'.)

I'm sure there's a technical word for the "base line of the text", but I'm not 
sure what it is. Am I making any sense?

(It is very possible that it isn't the job of freetype-go to do this 
computation, and that it's up to me to do it. I'm just not sure how.)

Once again, thanks! Your patch is appreciated.

Maintainers: is there any chance of getting this patch applied upstream?

Original comment by [email protected] on 7 Jun 2012 at 2:19

from freetype-go.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 15, 2024
Oh, right, I got distracted and forgot about height. I'll take another try at 
it.

Original comment by [email protected] on 7 Jun 2012 at 2:48

from freetype-go.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 15, 2024
Well thinking some more, I see that I totally screwed this up, not even the 
signature is right. The correct signature would probably be 
MeasureString(string) (canvas image.Point, start raster.Point), so that a 
caller like you can use it to decide how big of a canvas to allocate and where 
to draw on it to ensure that all pixels are shown.

example/freetype/main.go shows an overly simplistic way of calculating the 
location of the next line of text, which is pt.Y += c.PointToFix32(*size * 
*spacing). For your purposes (allocating the minimal canvas) you don't want to 
fudge it with a spacing factor, but actually know the farthest down from your 
origin point that pixels will be drawn. That dimension is known to DrawString 
down inside of it's per rune loop, so calculating it in MeasureString should be 
possible as well.

Original comment by [email protected] on 7 Jun 2012 at 3:30

from freetype-go.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 15, 2024
Don't hold your breath for an update to the patch; I'm not familiar enough with 
this code to make it work in the time I have available. Sorry.

Original comment by [email protected] on 7 Jun 2012 at 4:24

from freetype-go.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 15, 2024
Actually, I don't think you screwed it up. raster.Point seems to be what 
freetype-go wants to return, and that it's up to the caller to convert them. 
(I've been doing that.) Maybe that should be changed, but I'll leave that up to 
the maintainer's discretion.

As for discovering point.Max.Y, perhaps I can use 'glyphRect' to compute it? 
i.e., in the per rune loop:

p.Y = max(p.Y, orig.Y + c.FUnitToFix32(glyphRect.Dy()))

Where 'orig' is a copy of the original point passed to DrawString.

Finally, a question for the maintainer: *should* this calculation of Y be the 
value returned by DrawString, or is this an entirely separate computation? As 
far as I can tell, the Y value returned is the same as the Y value put in, so 
perhaps this computation is desirable.

When I get home, I'll work on another patch that tries to incorporate these 
changes.

Original comment by [email protected] on 7 Jun 2012 at 4:27

from freetype-go.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 15, 2024
No worries Jeff, thanks a lot for your help! You shoved me in the appropriate 
direction :-)

Original comment by [email protected] on 7 Jun 2012 at 4:28

from freetype-go.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 15, 2024
Yeah, package freetype needs to expose font metrics in some way. I'd rather 
hold off on that until the hinting code lands, though, as hinting affects 
metrics. Hinting has recently pushed the scale computation out of package 
freetype and into package truetype.

Also, golang-dev mail from long, long ago notes that ideally the API would let 
you e.g. change font colors while preserving kerning. Thus, the actual API 
design might need some deep thought.

Sorry for the late response, but I had a typo in my mail setup and wasn't 
getting freetype-go bug mail.

Original comment by [email protected] on 2 Aug 2012 at 1:39

  • Changed state: Accepted

from freetype-go.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 15, 2024
Okay, I've finally cobbled something together that appears to work. I've added 
a separate MeasureString method, which I hope returns the width/height of the 
bounding box containing the text provided.

I know next to nothing about font rendering and hacked this together based on 
other code in the package. It's likely I've done something wrong, but I thought 
it'd be nice to get this issue rolling. It's really awkward to render text 
without it.

I'm hoping that this, or something similar, will be added to freetype-go. For 
now, I have a clone: http://code.google.com/r/jamslam-freetype-go/

Nigel: comments are welcome!

Original comment by [email protected] on 16 Dec 2012 at 5:47

Attachments:

from freetype-go.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 15, 2024
Hello All, I'm curious if this is still holding on additional code before being 
added to the package. Is the patch provided the only means of getting this sort 
of functionality added?

Original comment by [email protected] on 16 Dec 2013 at 4:53

from freetype-go.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 15, 2024
As far as I know, yes. I'm still actively using my fork (jamslam-freetype-go) 
in my window manager until it gets fixed upstream.

Original comment by [email protected] on 17 Dec 2013 at 12:31

from freetype-go.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 15, 2024
Yes, hinting isn't completely implemented yet. It's a lot closer than when 
comment #9 was written, but it's still not complete.

Original comment by [email protected] on 17 Dec 2013 at 11:42

from freetype-go.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 15, 2024
The vg package from gonum/plot has code for computing these metrics.
You can find it here: https://github.com/gonum/plot/blob/master/vg/font.go.

It works OK, but it's not exactly right. For one, the scaling is a hack that I 
mostly made up. Everything else I tried didn't seem to work. I am also 
suspicious of the bounding boxes that freetype-go computes. They seem to be too 
big in the Y direction. At least, visually, they seem larger than line heights 
for the same fonts by other programs. This isn't a big problem unless you want 
to draw highlighted text with a shaded background.

Original comment by [email protected] on 16 Feb 2015 at 4:39

from freetype-go.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 15, 2024
I think that the bounding boxes are "too tall" for use as ascent and descent 
because they are computed from the bounds in the head table. Ascent and 
descent, for horizontal fonts should come from the hhea table. Would it be 
possible to expose this information?

Original comment by [email protected] on 16 Feb 2015 at 6:02

from freetype-go.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 15, 2024
In fact, I'll just open a separate issue for it.

Original comment by [email protected] on 16 Feb 2015 at 8:10

from freetype-go.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.