VFont: Use BLF for font & glyph loading #110187

Merged
Harley Acheson merged 22 commits from Harley/blender:vfontblf into main 2023-11-23 18:12:15 +01:00
Member

Load VFont curves using BLF API rather than local FreeType calls.


Text objects currently use the FreeType library directly. This is a duplication of code and also means that this area cannot take advantage of the more complex features of the BLF API. This PR allows VFont to use BFont.

This means that they can use the font, face, and lookup caches and have access to all the other BLF features. This also means that the default 3D Text font can participate in the fallback stack, so new users using the default font won't be frustrated with only having 239 characters, but instead have access to more than a hundred thousand of them. And also means I can later add support for variable axes features.

image

And if they select something that is not in any of the fallback fonts it will load a "last resort" glyph that contains information about what is missing, not just nothing or a "tofu" square. Following shows entering characters from the Duployan and Wancho alphabets:

image

In order for this to work we just need three new members added to the BLF API:

  • BLF_display_name - the font's family and style names are required for the VFontData object
  • BLF_get_vfont_metrics - needed to get the vfont initial size.
  • BLF_character_to_curves - convert a Unicode character into curves

With BLF_get_vfont_metrics the current code is just copied from vfont so the values, and therefore the initial sizes of the text objects, remain exactly as they are now.

For BLF_character_to_curves the entirety of the existing freetype_outline_to_curves is simply moved to blf_glyph.cc, renamed blf_glyph_to_curves, along with the extensive existing comments about the process. There is a helper function blf_character_to_curves added that takes a Unicode character, gets a glyph from the font (and from the font stack if not found), calls blf_glyph_to_curves and returns the scaled advance.

There are some small changes in blf_glyph.cc mostly to handle getting outlines without rasterizing, and without needing to use GlyphCacheBLF at all. Otherwise there isn't too much to this.

Load VFont curves using BLF API rather than local FreeType calls. --- Text objects currently use the FreeType library directly. This is a duplication of code and also means that this area cannot take advantage of the more complex features of the BLF API. This PR allows VFont to use BFont. This means that they can use the font, face, and lookup caches and have access to all the other BLF features. This also means that the default 3D Text font can participate in the fallback stack, so new users using the default font won't be frustrated with only having 239 characters, but instead have access to more than a hundred thousand of them. And also means I can later add support for variable axes features. ![image](/attachments/19670109-e532-458f-a482-312aa17a51b8) And if they select something that is not in any of the fallback fonts it will load a "last resort" glyph that contains information about what is missing, not just nothing or a "tofu" square. Following shows entering characters from the Duployan and Wancho alphabets: ![image](/attachments/4942f24e-e19a-44ce-b59b-ec7f0171cf81) In order for this to work we just need three new members added to the BLF API: * BLF_display_name - the font's family and style names are required for the VFontData object * BLF_get_vfont_metrics - needed to get the vfont initial size. * BLF_character_to_curves - convert a Unicode character into curves With `BLF_get_vfont_metrics` the current code is just copied from vfont so the values, and therefore the initial sizes of the text objects, remain exactly as they are now. For `BLF_character_to_curves` the entirety of the existing `freetype_outline_to_curves` is simply moved to blf_glyph.cc, renamed `blf_glyph_to_curves`, along with the extensive existing comments about the process. There is a helper function `blf_character_to_curves` added that takes a Unicode character, gets a glyph from the font (and from the font stack if not found), calls `blf_glyph_to_curves` and returns the scaled advance. There are some small changes in `blf_glyph.cc` mostly to handle getting outlines without rasterizing, and without needing to use GlyphCacheBLF at all. Otherwise there isn't too much to this.
178 KiB
141 KiB
Harley Acheson added this to the User Interface project 2023-07-17 03:37:53 +02:00
First-time contributor

is arabic there ?

is arabic there ?
Author
Member

@hamza-el-barmaki - is arabic there ?

The answer is "no" to the question that you are probably really asking, in that this does not enable LTR/RTL reordering or text shaping. But "yes" in that an Arabic font is in our fallback stack, so it is easier to get to those characters.

A common thing for new users to do is just Add / Text then try copying in emoji, symbols, or characters from their own language. Unfortunately the default font that we include for this purpose (Bfont Regular) contains very few characters so nothing comes out. Users eventually figure out that they need to select some other font in order to see anything nice.

This patch loads characters the same way the interface does. So if you type a character not in that font it will look in the fallback stack of fonts. So almost anything you can think of will come out. With Arabic they would come out backwards and bad, but at least something comes out. Enough that it might prompt you to try a precomposed string instead.

> @hamza-el-barmaki - is arabic there ? The answer is "no" to the question that you are probably really asking, in that this does **not** enable LTR/RTL reordering or text shaping. But "yes" in that an Arabic font is in our fallback stack, so it is easier to get to those characters. A common thing for new users to do is just Add / Text then try copying in emoji, symbols, or characters from their own language. Unfortunately the default font that we include for this purpose (Bfont Regular) contains very few characters so nothing comes out. Users eventually figure out that they need to select some other font in order to see anything nice. This patch loads characters the same way the interface does. So if you type a character not in that font it will look in the fallback stack of fonts. So almost anything you can think of will come out. With Arabic they would come out backwards and bad, but at least _something_ comes out. Enough that it might prompt you to try a precomposed string instead.
Harley Acheson changed title from WIP: VFont: Use BLF for font & glyph loading to VFont: Use BLF for font & glyph loading 2023-07-18 00:56:58 +02:00
Harley Acheson requested review from Campbell Barton 2023-07-18 00:57:10 +02:00
Harley Acheson force-pushed vfontblf from dd8e898d8a to 69db77403c 2023-07-31 03:50:59 +02:00 Compare
Harley Acheson added 2 commits 2023-09-08 21:36:27 +02:00
Pablo Vazquez added the
Module
User Interface
label 2023-09-13 18:03:46 +02:00
Harley Acheson added 1 commit 2023-10-05 02:08:29 +02:00
Author
Member

@JulianEisel - You had asked if this uses the glyph cache, and it does not. From the vfont side it loads fonts in the same way as for bfont, but then glyph outlines are loaded directly from them, with no need for the glpyh cache. And yes, this would all allow us to do the variable and synthetic changes as seen here, but for vfont: #112454. So we could have sliders for weight, width, slant, etc.

@JulianEisel - You had asked if this uses the glyph cache, and it does not. From the vfont side it loads fonts in the same way as for bfont, but then glyph outlines are loaded directly from them, with no need for the glpyh cache. And yes, this would all allow us to do the variable and synthetic changes as seen here, but for vfont: #112454. So we could have sliders for weight, width, slant, etc.
Harley Acheson changed title from VFont: Use BLF for font & glyph loading to WIP: VFont: Use BLF for font & glyph loading 2023-10-06 23:20:17 +02:00
Author
Member

There would be no need for vfontdata_freetype.cc to have access to FT_Face or FT_GlyphSlot with a few more BLF calls (face name, some unscaled metrics), and moving freetype_outline_to_curves to BLF as something like BLF_character_as_curves(int fontid, uint character, ListBase *nurbs, const float scale)

And this would work well with BLF_character_weight, BLF_character_slant, BLF_character_width, BLF_character_spacing of #112454

Both this and #112454 would need access to unscaled metrics so the FontInfo introduced there would work for this.

There would be no need for vfontdata_freetype.cc to have access to FT_Face or FT_GlyphSlot with a few more BLF calls (face name, some unscaled metrics), and moving `freetype_outline_to_curves` to BLF as something like BLF_character_as_curves(int fontid, uint character, ListBase *nurbs, const float scale) And this would work well with BLF_character_weight, BLF_character_slant, BLF_character_width, BLF_character_spacing of #112454 Both this and #112454 would need access to unscaled metrics so the FontInfo introduced there would work for this.
Harley Acheson added 3 commits 2023-10-15 04:55:10 +02:00
Harley Acheson added 1 commit 2023-10-15 05:10:19 +02:00
Harley Acheson added 1 commit 2023-10-15 05:32:07 +02:00
Harley Acheson changed title from WIP: VFont: Use BLF for font & glyph loading to VFont: Use BLF for font & glyph loading 2023-10-19 23:47:14 +02:00
Harley Acheson added 1 commit 2023-11-12 19:16:27 +01:00
Harley Acheson added 2 commits 2023-11-13 18:48:28 +01:00
Harley Acheson added 1 commit 2023-11-20 23:18:20 +01:00
Harley Acheson added 1 commit 2023-11-21 00:45:34 +01:00
Harley Acheson added 2 commits 2023-11-23 00:17:49 +01:00
Harley Acheson added 1 commit 2023-11-23 00:49:41 +01:00
Harley Acheson added 1 commit 2023-11-23 01:02:01 +01:00
buildbot/vexp-code-patch-coordinator Build done. Details
7ba4f8fa70
Cleanup, formatting.
Author
Member

@blender-bot build

@blender-bot build
Harley Acheson added 1 commit 2023-11-23 01:52:13 +01:00
buildbot/vexp-code-patch-coordinator Build done. Details
ff80edcf71
calming warnings
Author
Member

@blender-bot build

@blender-bot build
Harley Acheson added 1 commit 2023-11-23 02:13:48 +01:00
buildbot/vexp-code-patch-coordinator Build done. Details
c006c2e84b
last sign conversion warnings?
Author
Member

@blender-bot build

@blender-bot build
Harley Acheson added 1 commit 2023-11-23 03:12:15 +01:00
buildbot/vexp-code-patch-coordinator Build done. Details
d2ef8506cc
Removing incorrect usage of ATTR_NONNULL attribute
Author
Member

@blender-bot build

@blender-bot build
Harley Acheson added 1 commit 2023-11-23 17:25:57 +01:00
Harley Acheson merged commit 604ee2d036 into main 2023-11-23 18:12:15 +01:00
Harley Acheson deleted branch vfontblf 2023-11-23 18:12:17 +01:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#110187
No description provided.