Commit Graph

105 Commits

Author SHA1 Message Date
Harley Acheson d2b1e4712d BLF: Mutex Lock Glyph Cache Per Font, Not Global
Only lock access to our glyph caches per-font, rather than globally.
Also upgrade from spinlocks to mutexes.

See D15644 for more details.

Differential Revision: https://developer.blender.org/D15644

Reviewed by Brecht Van Lommel
2022-08-11 12:52:07 -07:00
Harley Acheson d3c653c6d9 BLF: Revert FreeType Cache
Remove the FreeType cache implementation. Not multithreading correctly.

Original commit: 9d77b5a0ed

See D15647 for more details.

Differential Revision: https://developer.blender.org/D15647

Own Code.
2022-08-08 20:33:43 -07:00
Harley Acheson 9d77b5a0ed BLF: Implement FreeType Caching
Implementation of the FreeType 2 cache subsystem, which limits the
number of concurrently-opened FT_Face and FT_Size objects, as well as
caching information like character maps to speed up glyph id lookups.

See D13137 for much more detail.

Differential Revision: https://developer.blender.org/D13137

Reviewed by Brecht Van Lommel
2022-08-04 13:05:19 -07:00
Harley Acheson c0845abd89 BLF: Fonts with FT_Face Optional
Allow FontBLFs to exist with NULL FT_Face, added only when actually
needed. Speeds up startup and unused fonts are not loaded.

See D15258 for more details.

Differential Revision: https://developer.blender.org/D15258

Reviewed by Brecht Van Lommel
2022-07-28 17:50:34 -07:00
Harley Acheson b9c0eed206 BLF: Add Support for Variable Fonts
Add support for Variable/Multiple Master font features. These are fonts
that contain a range of design variations along multiple axes. This
contains no client-facing options.

See D12977 for details and examples

Differential Revision: https://developer.blender.org/D12977

Reviewed by Brecht Van Lommel
2022-07-07 12:59:16 -07:00
Harley Acheson 228d79b789 Revert 6de0f299505a: BLF: Support for Variable Fonts
Reverting for now, breaks on GCC
2022-06-27 06:32:30 -07:00
Harley Acheson 6de0f29950 BLF: Add Support for Variable Fonts
Add support for Variable/Multiple Master font features. These are fonts
that contain a range of design variations along multiple axes. This
contains no client-facing options.

See D12977 for details and examples

Differential Revision: https://developer.blender.org/D12977

Reviewed by Brecht Van Lommel
2022-06-27 06:07:55 -07:00
Harley Acheson 524a9e3db8 BLF: Fallback Font Stack
Allow use of multiple fonts acting together like a fallback stack,
where if a glyph is not found in one it can be retrieved from another.

See D12622 for much more detail

Differential Revision: https://developer.blender.org/D12622

Reviewed by Brecht Van Lommel
2022-06-17 10:31:48 -07:00
Campbell Barton 2c75857f9f Cleanup: spelling in comments, use doxygen comments 2022-05-06 17:56:59 +10:00
Harley Acheson 8826db8f03 Fix T97310: BLF Line Height While Text Wrapping
Fix word-wrapped tooltip text not showing by aligning to pixel grid.

See D14639 for more details.

Differential Revision: https://developer.blender.org/D14639

Reviewed by Campbell Barton
2022-04-13 17:45:32 -07:00
Campbell Barton 21ae323dbf Cleanup: avoid redundant float/int conversions in BLF
Internally many offsets for BLF were integers but exposed as floats,
since these are used in pixel-space, many callers were converging them
back to integers. Simplify logic by using ints.
2022-04-13 13:06:29 +10:00
Campbell Barton ae43872ad5 BLF: sub-pixel positioning support
Support sub-pixel kerning and hinting for future support for improved
character placement. No user visible changes have been made.

- Calculate sub-pixel offsets, using integer maths.
- Use convenience functions to perform the conversions and hide the
  underlying values.
- Use `ft_pix` type to distinguish values that use sub-pixel integer
  values from freetype and values rounded to pixels.

This was originally based on D12999 by @harley with the user visible
changes removed so they can be applied separately.
2022-04-13 11:58:42 +10:00
Campbell Barton 4682a0882f Cleanup: use "filepath" instead of "filename" for full paths
Reserve "filename" when only the name component is used.
2022-03-24 16:54:01 +11:00
Campbell Barton c434782e3a File headers: SPDX License migration
Use a shorter/simpler license convention, stops the header taking so
much space.

Follow the SPDX license specification: https://spdx.org/licenses

- C/C++/objc/objc++
- Python
- Shell Scripts
- CMake, GNUmakefile

While most of the source tree has been included

- `./extern/` was left out.
- `./intern/cycles` & `./intern/atomic` are also excluded because they
  use different header conventions.

doc/license/SPDX-license-identifiers.txt has been added to list SPDX all
used identifiers.

See P2788 for the script that automated these edits.

Reviewed By: brecht, mont29, sergey

Ref D14069
2022-02-11 09:14:36 +11:00
Harley Acheson bb3bcf744c BLF: Save fixed_width value in cache
Cache the font size's ideal fixed width column size in the glyph cache
rather than the font itself to improve performance.

See D13226 for more details.

Differential Revision: https://developer.blender.org/D13226

Reviewed by Campbell Barton
2022-02-04 17:49:21 -08:00
Harley Acheson 73047c69ea BLF: Use Floats for Font Point Sizes
Allow the use of floating-point values for font point sizes, which
allows greater precision and flexibility for text output.

See D8960 for more information, details, and justification.

Differential Revision: https://developer.blender.org/D8960

Reviewed by Campbell Barton
2021-11-13 09:39:18 -08:00
Harley Acheson c4b73847d3 BLF: Remove Thread Locking For Font Metrics
This patch removes the need to lock the thread just to get to some
generic (not glyph-specific) font metrics.

See D12976 for more details.

Differential Revision: https://developer.blender.org/D12976

Reviewed by Campbell Barton
2021-11-02 14:28:25 -07:00
Campbell Barton df8f507f41 Cleanup: spelling in comments 2021-10-06 14:54:05 +11:00
Harley Acheson 0d7aab2375 Refactor: BLF Kerning Cache After Use
Optimization of font kerning by only caching kerning values after a
pair is encountered. Also saves unscaled values so they don't have to
be rebuilt between font size changes.

See D12274 for more details and speed comparison.

Differential Revision: https://developer.blender.org/D12274

Reviewed by Campbell Barton
2021-08-20 17:48:42 -07:00
Harley Acheson 22ab0159a9 Refactor: BLF Without Kerning Modes
Simplification of BLF code after removal of kerning modes.

See D12262 for more details.

Differential Revision: https://developer.blender.org/D12262

Reviewed by Campbell Barton
2021-08-18 20:31:47 -07:00
Campbell Barton 4300050e20 Cleanup: rename kerning table to ascii_table
It wasn't obvious this was only for ASCII characters.
2021-08-16 14:35:38 +10:00
Harley Acheson d5261e973b BLF: Do Not Preload Glyph Cache
This patch turns off the preloading of ascii glyphs and instead caches
each glyph the first time it is actually used.

See D12215 for much more detail.

Differential Revision: https://developer.blender.org/D12215

Reviewed by Campbell Barton
2021-08-14 13:50:51 -07:00
Harley Acheson 6a4533dd02 BLF Cleanup: Size Defines, Comments, etc
This patch makes some non-functional changes to BLF code. Some size
defines added, comments changed, simplification of macro
BLF_KERNING_VARS.

See D12200 for more details.

Differential Revision: https://developer.blender.org/D12200

Reviewed by Campbell Barton
2021-08-13 14:31:10 -07:00
Harley Acheson cd1bb63159 BLF: Do Not Cache Unused Rendered Glyphs
The loading of a font size or style renders bitmaps of the characters
0-255 and stores them in a cache. But glyphs 128-255 in this cache are
not accessible. What used to be ansi high-bit characters are now multi-
byte UTF-8 sequences.

Therefore this patch reduces the glyph_ascii_table size to 128 and
only caches characters 32-127, the visible portion of ASCII, which
greatly reduces the time to load a font.

See D12189 for more details.

Differential Revision: https://developer.blender.org/D12189

Reviewed by Campbell Barton
2021-08-11 13:55:58 -07:00
Jacques Lucke 91694b9b58 Code Style: use "#pragma once" in source directory
This replaces header include guards with `#pragma once`.
A couple of include guards are not removed yet (e.g. `__RNA_TYPES_H__`),
because they are used in other places.

This patch has been generated by P1561 followed by `make format`.

Differential Revision: https://developer.blender.org/D8466
2020-08-07 09:50:34 +02:00
Harley Acheson b74cc23dc4 UI: Ability to Print Bold and Italics
Adds the ability to print text in bold or italics style, synthesized from a single base UI font.

Differential Revision: https://developer.blender.org/D7893

Reviewed by Brecht Van Lommel
2020-06-05 15:39:17 -07:00
Campbell Barton ccaab72685 BLF: use 'int' for internal glyph x,y bearing
These were stored as float but were originally cast from an int
and were often cast back to int.

Also use int pairs for dimensions values.
2020-05-03 18:01:20 +10:00
Dalai Felinto 2d1cce8331 Cleanup: `make format` after SortedIncludes change 2020-03-19 09:33:58 +01:00
Germano Cavalcante 41dbb06b76 Fix T74228, T74246: Strange Characters
The glyph can come from a different cache.
2020-02-27 10:55:07 -03:00
Germano Cavalcante 001f7c92d1 BLF: Optimize text rendering and caching
The current code allocates and transfers a lot of memory to the GPU,
but only a small portion of this memory is actually used.
In addition, the code calls many costly gl operations during the
caching process.

This commit significantly reduce the amount of memory by allocating
and transferring a flat array without pads to the GPU.
It also calls as little as possible the gl operations during the cache.

This code also simulate a billinear filter `GL_LINEAR` using a 1D texture.

**Average drawing time:**
|before:|0.00003184 sec
|now:|0.00001943 sec
|fac:|1.6385156675048407

**5 worst times:**
|before:|[0.001075, 0.001433, 0.002143, 0.002915, 0.003242]
|now:|[0.00094, 0.000993, 0.001502, 0.002284, 0.002328]

Differential Revision: https://developer.blender.org/D6886
2020-02-24 08:01:22 -03:00
Campbell Barton 76e6d2f19d Cleanup: spelling
Also remove historic bftgl reference.
2019-10-17 12:40:36 +11:00
Richard Antalik a960dc4519 BLF: make library glyph cache handling thread-safe
Functions that utilize glyph cache should lock and unlock cache by
calling `blf_glyph_cache_acquire()` and `blf_glyph_cache_release()`.
Function `blf_glyph_cache_acquire()` will create glyph cache, if it doesn't exist.
Locking mutex is global and shared by all fonts.

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D5701
2019-09-13 17:24:42 -07:00
Campbell Barton e12c08e8d1 ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211.

For details on usage and instructions for migrating branches
without conflicts, see:

https://wiki.blender.org/wiki/Tools/ClangFormat
2019-04-17 06:21:24 +02:00
Campbell Barton de13d0a80c doxygen: add newline after \file
While \file doesn't need an argument, it can't have another doxy
command after it.
2019-02-18 08:22:12 +11:00
Campbell Barton eef4077f18 Cleanup: remove redundant doxygen \file argument
Move \ingroup onto same line to be more compact and
make it clear the file is in the group.
2019-02-06 15:45:22 +11:00
Campbell Barton 65ec7ec524 Cleanup: remove redundant, invalid info from headers
BF-admins agree to remove header information that isn't useful,
to reduce noise.

- BEGIN/END license blocks

  Developers should add non license comments as separate comment blocks.
  No need for separator text.

- Contributors

  This is often invalid, outdated or misleading
  especially when splitting files.

  It's more useful to git-blame to find out who has developed the code.

See P901 for script to perform these edits.
2019-02-02 01:36:28 +11:00
Richard Antalik b3dbe17658 Add font selection to VSE text strips
Allows users to select a font for text strips in the video sequence editor.

Related: 3610f1fc43 Sequencer: refactor clipboard copy to no longer increase user count.

Reviewed by: Brecht

Differential Revision: https://developer.blender.org/D3621
2019-01-13 21:57:09 -08:00
Clément Foucault 8cd7828792 GWN: Port to GPU module: Replace GWN prefix by GPU 2018-07-18 11:49:15 +02:00
Clément Foucault 247ad2034d GWN: Port to GPU module: Move files to GPU
This does not include all the struct and type renaming. Only files were
renamed.

gwn_batch.c/h was fusioned with GPU_batch.c/h
gwn_immediate.c/h was fusioned with GPU_immediate.c/h
gwn_imm_util.c/h was fusioned with GPU_immediate_util.c/h
2018-07-18 00:17:57 +02:00
Campbell Barton c517778a8b Cleanup: style 2018-06-22 08:18:02 +02:00
Ray Molenkamp 84ae0fe3a5 GLRefactor: Refactor bf_blenfont to use GPUTexture instead of raw GL calls and types.
In an effort to centralize all opengl calls in the codebase, this patch replaces
the raw opengl calls in bf_blenfont with GPUTexture so it's no longer depended
on opengl headers.

reviewer: Brecht

Differential Revision: https://developer.blender.org/D3483
2018-06-21 18:36:05 -06:00
Campbell Barton 908b6960c0 Merge branch 'master' into blender2.8 2018-06-08 08:10:35 +02:00
Campbell Barton a25c11fd8d Cleanup: trailing space
Remove from blender/nodes, collada, blenfont & render.
2018-06-08 08:07:48 +02:00
Campbell Barton bfe1d0e0dc Merge branch 'master' into blender2.8 2018-06-01 18:26:42 +02:00
Campbell Barton 75fc1c3507 Cleanup: trailing whitespace (comment blocks)
Strip unindented comment blocks - mainly headers to avoid conflicts.
2018-06-01 18:19:39 +02:00
Campbell Barton 122d0d1504 Cleanup: style 2018-04-21 20:42:27 +02:00
Clément Foucault 0b5ebb3265 BLF: Fix problem with bound texture.
Previous code was assuming that the glyph texture would remain bound to
GL_TEXTURE0 until the cache would be drawn. This is not always the case,
so better save the texture and rebind it before drawing.
2018-04-08 01:14:43 +02:00
Campbell Barton b65ea517eb Merge branch 'master' into blender2.8
- Undo that changes modes currently asserts,
  since undo is now screen data.

  Most likely we will change how object mode and workspaces work
  since it's not practical/maintainable at the moment.

- Removed view_layer from particle settings
  (wasn't needed and complicated undo).
2018-04-01 11:03:25 +02:00
Clément Foucault f9691bae84 BLF: Perf: Add a kerning cache table for ascii chars.
This adds less than a megabyte of mem usage.
FT_Get_Kerning was the 2nd hotspot when profilling. This commit completly
remove this cost.

One concern though: I don't know if the kerning data is constant for every
sizes but it seems to be the case. I tested different fonts at different
dpi scalling and saw no differences.
2018-03-31 19:32:53 +02:00
Campbell Barton 22d40fdfd8 Cleanup: blf internal struct naming
- use x/y/width/height/max as a suffix.
- replace 'num' prefix /w 'len' suffix.
2018-03-31 13:40:23 +02:00