Comments (8)
Yeah this is complex and I'm still learning here. But in short, if you want to do anything with text except rendering you have to go through BLGlyphBuffer
. I have added a small example to Getting Started page that uses glyph-buffer.
Terminology:
BLFontFace
- design font that represents a singlettf
orotf
file or a single font in a font collectionBLFontDesignMetrics
- design metrics stored inBLFontFace
BLFont
- scaledBLFontFace
into the user providedsize
BLFontMetrics
- scaled font metrics that respect user providedsize
BLGlyphBuffer
- allows to convert unicode text to glyphs, a container that holds glyphs and their positionsBLGlyphRun
- data structure that contains glyphs and possibly their placementBLGlyphItem
andBLGlyphInfo
- these two are equivalent tohb_glyph_info_t
of harfbuzzBLTextMetrics
- metrics of text or glyphs
Basically to measure text you need a glyph-run, to render text you need a glyph-run, basically to do anything with text you need to convert text into glyphs so Blend2D makes this explicit and requires users to use BLGlyphBuffer
. I tried to make this as less painful as possible and I welcome suggestions.
from blend2d.
The one piece im not sure of is the conversions. The glyph run gives 'advance, as a big number. Should i divide that by 64, 92, 96, 120, or some other font related factor to get pixels?
from blend2d.
I think this is a bit messy still. In general GlyphBuffer works with design units, but when you ask for TextMetrics that should get scaled to user units (the size of the font). I have to check how harfbuzz deals with this as I'm not really sure 100% myself how this should work.
When you render text then the rendering context would automatically take care of this so you get what you want, measuring is the problem I would say.
BTW: You should update your Blend2D source as I have fixed getTextMetrics
to return scaled metrics, in the initial beta it was not scaled and thus wrong.
from blend2d.
Ah yes, that is the problem. I had first used text metrics, and was getting design (non-scaled) values. I'll update and see what's what. I realize this is a quick and dirty "toy" way to measure text, but it helps at least doing quick and dirty UI stuff.
from blend2d.
I have confirmed that getTextMetrics seems to be giving a scaled result. The bounding box still does not seem correct though. The x0 and x1 are correct, but the y0 and y1 return a value of 0. I use the font height (font.impl.metrics.size) to fillin for that temporarily.
from blend2d.
Yeah this is true, I actually don't know whether text metrics should calculate the exact vertical bounding box or whether it should default to something like [-ascent, descent]. I would definitely need some help in this area as I'm no expert on typography (yet:))
from blend2d.
fonts get very tricky very fast with plenty of esoterica mixed in over the centuries. I'm going to stick with the font.impl.metrics.size thing for now. Perhaps this is an area left to those fancy font/text layout engines. Provide all the necessary font, glyph information you parse, and let the true believers build the super correct stuff. Meanwhile, your 'toy' can do a few things well, and call it a day.
by 'toy', I'm referring to the simple text measurement in the same way the Cairo 'toy' text measuring is referred to, not meant to disparage the entirety of the work.
from blend2d.
I'll close this specific issue now and open a separate issue for more specific font measurement challenges.
from blend2d.
Related Issues (20)
- img.getData 0.9.0 to 0.10.5 version HOT 4
- Wish: implement an API to rendering text along/by a path HOT 1
- composition operator not work on macOS MPB with Apple m1 HOT 2
- [Portable Pipeline] Composition operators not working (only SrcCopy and SrcOver) HOT 11
- Rendering bug with BLContext for certain image sizes HOT 2
- Wish: Android support HOT 2
- Raspberry Pi 2B rev1.1 compilation failed HOT 3
- about BLFont question HOT 12
- strokedPath error HOT 1
- Can bled2d be easily ported to rtos? HOT 3
- Rendering of fonts in various national languages HOT 2
- Build failure simdx86_test_avx512.cpp, MingGW-w64, static, cmake/ninja, no tests HOT 4
- clipToRect not correctly applied to fillGlyphRun within rotated context HOT 4
- crash with gcc (Debian 12.2.0-14) 12.2.0 HOT 4
- build errors on Fedora s390x HOT 1
- Crash on blitImage with different image format HOT 3
- ctest of bl_test_unit failed on fedora s390x HOT 5
- Support 8-bit (s)RGBA BLImages? HOT 5
- Unexpected results with BLPattern HOT 2
- close() on path doesn't interact with stroking as expected. HOT 2
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 blend2d.