Giter VIP home page Giter VIP logo

Comments (8)

kobalicek avatar kobalicek commented on May 27, 2024

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 single ttf or otf file or a single font in a font collection
  • BLFontDesignMetrics - design metrics stored in BLFontFace
  • BLFont - scaled BLFontFace into the user provided size
  • BLFontMetrics - scaled font metrics that respect user provided size
  • BLGlyphBuffer - allows to convert unicode text to glyphs, a container that holds glyphs and their positions
  • BLGlyphRun - data structure that contains glyphs and possibly their placement
  • BLGlyphItem and BLGlyphInfo - these two are equivalent to hb_glyph_info_t of harfbuzz
  • BLTextMetrics - 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.

Wiladams avatar Wiladams commented on May 27, 2024

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.

kobalicek avatar kobalicek commented on May 27, 2024

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.

Wiladams avatar Wiladams commented on May 27, 2024

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.

Wiladams avatar Wiladams commented on May 27, 2024

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.

kobalicek avatar kobalicek commented on May 27, 2024

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.

Wiladams avatar Wiladams commented on May 27, 2024

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.

Wiladams avatar Wiladams commented on May 27, 2024

I'll close this specific issue now and open a separate issue for more specific font measurement challenges.

from blend2d.

Related Issues (20)

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.