Comments (16)
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
- Added labels: ****
- Removed labels: ****
from freetype-go.
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
- Added labels: ****
- Removed labels: ****
Attachments:
from freetype-go.
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
- Added labels: ****
- Removed labels: ****
from freetype-go.
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
- Added labels: ****
- Removed labels: ****
from freetype-go.
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
- Added labels: ****
- Removed labels: ****
from freetype-go.
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
- Added labels: ****
- Removed labels: ****
from freetype-go.
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
- Added labels: ****
- Removed labels: ****
from freetype-go.
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
- Added labels: ****
- Removed labels: ****
from freetype-go.
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
- Added labels: ****
- Removed labels: ****
from freetype-go.
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
- Added labels: ****
- Removed labels: ****
Attachments:
from freetype-go.
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
- Added labels: ****
- Removed labels: ****
from freetype-go.
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
- Added labels: ****
- Removed labels: ****
from freetype-go.
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
- Added labels: ****
- Removed labels: ****
from freetype-go.
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
- Added labels: ****
- Removed labels: ****
from freetype-go.
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
- Added labels: ****
- Removed labels: ****
from freetype-go.
In fact, I'll just open a separate issue for it.
Original comment by [email protected]
on 16 Feb 2015 at 8:10
- Added labels: ****
- Removed labels: ****
from freetype-go.
Related Issues (16)
- Easier packaging HOT 2
- request: truetype font Name() API
- Fix TTC parsing HOT 1
- Potential MSIRP implementation issue in hint.go HOT 3
- DeltaP / DeltaC implementation questions HOT 1
- unable to get glyph bounding box
- Expose ascent and descent in truetype.Font. HOT 1
- Artifacts close to start/end points HOT 4
- join/cap stroke polyline HOT 2
- goinstall: image/draw HOT 2
- Neither release go or weekly go will compile/install... HOT 2
- SetSrc only makes sense if it's image.Uniform HOT 1
- Install error in my ubuntu 11.04 HOT 1
- OpenSans font compatability
- Patch for /freetype/freetype.go HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from freetype-go.