Commit Graph

842 Commits

Author SHA1 Message Date
Campbell Barton c9144f0cbb Fix potential undefined behavior printing a NULL pointer string
Improve messages when the font directory can't be detected or is missing.
2022-08-22 12:10:41 +10:00
Harley Acheson acf083a5bf BLF: Fix FT_Get_Advance Wrong Value Without Size
Fix possibility of getting invalid fixed-pitch advance size.

See D15735 for more details.

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

Own Code.
2022-08-19 17:16:22 -07:00
Campbell Barton 0322802314 Cleanup: minor changes to BLF API
- Use upper-case for defines.
- Use u-prefix for unsigned types.
- Use snake case for struct members.
- Use const struct for unicode_blocks & arguments.
- Use doxy style comments for struct members.
- Add doxy sections for recently added code.
- Correct code-comments (outdated references).
- Remove 'e' prefix from struct UnicodeBlock/FaceDetails
  (normally used for enums).
2022-08-19 14:46:45 +10:00
Campbell Barton 1a3bc09e89 Cleanup: spelling in comments 2022-08-19 13:49:13 +10:00
Harley Acheson d772e11b5a BLF: Gamma Correction
Gamma correction for glyph coverage values.

See D13376 for details and examples.

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

Reviewed by Julian Eisel
2022-08-18 12:34:23 -07:00
Campbell Barton 29c1d736c4 Cleanup: compiler warnings, clang-tidy 2022-08-17 11:57:53 +10:00
Harley Acheson d39abb74a0 BLF: FreeType Optional 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.
This time with the option of opening FontBLFs that are not cached.

See D15686 for more details.

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

Reviewed by Brecht Van Lommel
2022-08-16 15:02:56 -07:00
Harley Acheson 09640ab291 Fix T99872: Crash Loading Embedded Fonts - Master
Commit rBc0845abd897f to 3.4 (master) uses font's filepath without
checking if it exists, therefore crashing on embedded fonts since
they do not have a filepath (loaded from memory).

See D15703 for more details

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

Reviewed by Brecht Van Lommel
2022-08-16 12:43:10 -07:00
Christian Rauch a296b8f694 GPU: replace GLEW with libepoxy
With libepoxy we can choose between EGL and GLX at runtime, as well as
dynamically open EGL and GLX libraries without linking to them.

This will make it possible to build with Wayland, EGL, GLVND support while
still running on systems that only have X11, GLX and libGL. It also paves
the way for headless rendering through EGL.

libepoxy is a new library dependency, and is included in the precompiled
libraries. GLEW is no longer a dependency, and WITH_SYSTEM_GLEW was removed.

Includes contributions by Brecht Van Lommel, Ray Molenkamp, Campbell Barton
and Sergey Sharybin.

Ref T76428

Differential Revision: https://developer.blender.org/D15291
2022-08-15 16:10:29 +02:00
Harley Acheson dcfe7f795c BLF: Adjustments to Static Font Details
Adjust static font details so that we can properly display Arabic
contextual letter forms. And so that alphabetical ligatures are loaded
from language-specific fonts.

See D15678 for more details

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

Own Code.
2022-08-12 11:57:53 -07:00
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 51381c94d8 BLF: Fallback Broken After Cache Removal
Font fallback feature not working after reverting the implementation
of the cache system. Missing an blf_ensure_face before
FT_Get_Char_Index. Otherwise glyphs not found in fonts without faces.

Own Code
2022-08-10 20:50:49 -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 8b3e3c1810 Fix T100242: Handle Flushed FT Sizes
Properly deal with FreeType cache flushing a font's ft_size. Set this
to NULL in finalizer, and add a blf_ensure_size to make sure it
exists only when needed.

See D15639 for more details.

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

Reviewed by Brecht Van Lommel
2022-08-08 17:23:25 -07:00
Hans Goudey 5b8143287b Fix: Build error after recent commit
A second try after 8b46731396.
2022-08-04 17:20:10 -05:00
Harley Acheson 8b46731396 Fix Build Warnings in blf_font.c
Function made static, unused argument, type conversion

Introduced in 9d77b5a0ed

Own Code.
2022-08-04 14:40:11 -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
Brecht Van Lommel cc12f3e0ba Cleanup: fix various typos
Contributed by luzpaz.

Differential Revision: https://developer.blender.org/D15588
2022-08-03 19:28:05 +02:00
Campbell Barton 4815772fda Cleanup: quiet warnings in recent BLF and rna_ui changes 2022-07-29 13:48:09 +10:00
Harley Acheson e9bd6abde3 BLF: New Font Stack for Better Language Coverage
Replace our existing two fonts with a stack of new fonts to increase
and improve language coverage and to add many new symbols and icons.
Covers glyphs of top 44 languages - 1.5 billion more potential users.

See D10887 for lots of details.

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

Reviewed by Brecht Van Lommel
2022-07-28 20:09:20 -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 848dd4a40a BLF: Don't Print Empty Strings
Optimize font drawing by skipping empty strings.

See D15472 for more details.

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

Reviewed by Campbell Barton
2022-07-28 17:28:05 -07:00
Campbell Barton 03173d63c0 Cleanup: spelling in comments
Also move mis-placed doc-string.
2022-07-08 09:48:49 +10:00
Harley Acheson 56bf92f0f6 Cleanup: Calm GCC Conversion Warning
Commit b9c0eed206 introduced a GCC conversion warning because of an
assignment of a long int value to an int.

Own Code
2022-07-07 14:29:37 -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
Campbell Barton 148dcb3954 Cleanup: spelling in comments 2022-07-04 15:26:57 +10:00
Campbell Barton 65f4f50640 Cleanup: compiler warnings, remove unused functions 2022-06-28 10:13:24 +10: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
Campbell Barton b8289eb1b9 Cleanup: replace BLF defines with enum, formatting 2022-06-22 14:50:22 +10:00
Ray Molenkamp 600c391a65 Cleanup: Compiler Warning of Sign Conversion #2
Second attempt to silence sign-conversion warning on Linux, introduced
in rB524a9e3db810. Confirmed fix on buildbot.
2022-06-17 13:59:25 -07:00
Harley Acheson 3d3c0dfe30 Cleanup: Compiler Warning of Sign Conversion
rB524a9e3db810 introduced sign-conversion warning on Linux.

Own Code
2022-06-17 12:46:37 -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 02de1bff1e Cleanup: warning for 'float' to 'int' with MSVC 2022-04-13 14:22:58 +10: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 0ef96cd392 Cleanup: ensure space after file named in headers
Add blank lines after file references to avoid them being interpreted as
doc-strings the following declarations.
2022-04-04 13:34:42 +10:00
Campbell Barton 4d46fac65d Cleanup: use count or num instead of nbr
Follow conventions from T85728.
2022-03-25 12:04:20 +11:00
Harley Acheson b030ec8760 BLF Cleanup: Use FreeType Enum FT_Err_Ok
Replace comparisons of FT_Error against 0 with FT_Err_Ok instead.

See D14052 for more details.

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

Reviewed by Campbell Barton
2022-03-24 16:20:10 -07: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 55c90df316 BLF: Enable Filtering of woff and woff2 Fonts
Add files with extension ".woff" and ".woff2" to FILE_TYPE_FTFONT
file type. Allows selecting and using these types of font files.

See D13822 for more details.

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

Reviewed by Campbell Barton
2022-02-08 08:43:01 -08:00
Harley Acheson 835dd95046 BLF: Cleanup blf_glyph_cache_find & blf_font_size
Removes unnecessary calls to blf_glyph_cache_find, simplifies
blf_font_size, and reduces calls to it. blf_glyph_cache_new
and blf_glyph_cache_find made static.

See D13374 for more details.

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

Reviewed by Campbell Barton
2022-02-04 18:32:32 -08:00
Harley Acheson b1cee36190 BLF: Default Size as Float
Allowing setting and storing of the default font size as float.

See D13230 for more details.

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

Reviewed by Campbell Barton
2022-02-04 18:05:25 -08:00
Harley Acheson fbd5b85456 BLF: Removal of blf_font_draw_ascii Declaration
Removal of declaration of unused blf_font_draw_ascii

See D13624 for more details.

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

Reviewed by Campbell Barton
2022-02-04 17:55:50 -08: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 2a967d444f BLF: blf_glyph_cache_free Made Static
blf_glyph_cache_free does not need to be public.

See D13395 for more details.

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

Reviewed by Campbell Barton
2022-02-04 17:37:23 -08:00
Aaron Carlisle e951e81b0f Cleanup: Cmake: remove unnecessary definitions for internationalization
Previously, macros were ifdefed using the cmake option `WITH_INTERNATIONAL`
However, the is unnecessary as withen the functions themselves have checks for building without internationalization.
This also means that many `add_definitions(-DWITH_INTERNATIONAL)` are also unnecessary.

Reviewed By: mont29, LazyDodo

Differential Revision: https://developer.blender.org/D13929
2022-01-29 17:40:27 -05:00
Campbell Barton b3bf46b78d Revert "CMake: include BROTLI_LIBRARIES in FREETYPE_LIBRARIES on UNIX"
This reverts commit 086f191169.

There was apparently a problem using APPEND which wasn't referenced
in the commit log.

Added comment noting the reason for the discrepancy.
2022-01-26 20:51:04 +11:00
Campbell Barton 086f191169 CMake: include BROTLI_LIBRARIES in FREETYPE_LIBRARIES on UNIX
This was already done for APPLE & WIN32, which would
reference these libraries twice.

Now append BROTLI_LIBRARIES to FREETYPE_LIBRARIES when they're
required for linking.

No functional changes as all references to FREETYPE_LIBRARIES also
used BROTLI_LIBRARIES.
2022-01-26 16:00:55 +11:00
Sybren A. Stüvel a000de7c2a CMake/Linux: find Brotli library the proper way
Use a `FindBrotli.cmake` module instead of manually appending library
paths.

This is just for Linux; Windows and macOS will be reviewed separately.
2022-01-25 11:34:13 +01:00
Ray Molenkamp c20f209b1c Cmake/Deps: Freetype 2.11.0 / brotli 1.0.9
The UI team requested adding woff2 support to freetype.
this required a new dependency brotli.

This changes adds brotili to the builder and bumps
freetype to version 2.11.0

As freetype now depends on other libraries, for consistency
all use of ${FREETYPE_LIBRARY} in cmake has been updated to
use ${FREETYPE_LIBRARIES} adjustments have been made in the
windows platform file, all other platforms use cmake's
FindFreeType.cmake which already sets this variable.

reviewed by: brecht

Differential Revision: https://developer.blender.org/D13448
2022-01-21 10:26:05 -07:00
Clément Foucault fb6bd88644 Revert "BLI: Refactor vector types & functions to use templates"
Includes unwanted changes

This reverts commit 46e049d0ce.
2022-01-12 12:50:02 +01:00
Clment Foucault 46e049d0ce BLI: Refactor vector types & functions to use templates
This patch implements the vector types (i.e:`float2`) by making heavy
usage of templating. All vector functions are now outside of the vector
classes (inside the `blender::math` namespace) and are not vector size
dependent for the most part.

In the ongoing effort to make shaders less GL centric, we are aiming
to share more code between GLSL and C++ to avoid code duplication.

####Motivations:
 - We are aiming to share UBO and SSBO structures between GLSL and C++.
 This means we will use many of the existing vector types and others
 we currently don't have (uintX, intX). All these variations were
 asking for many more code duplication.
 - Deduplicate existing code which is duplicated for each vector size.
 - We also want to share small functions. Which means that vector
 functions should be static and not in the class namespace.
 - Reduce friction to use these types in new projects due to their
 incompleteness.
 - The current state of the `BLI_(float|double|mpq)(2|3|4).hh` is a
 bit of a let down. Most clases are incomplete, out of sync with each
 others with different codestyles, and some functions that should be
 static are not (i.e: `float3::reflect()`).

####Upsides:
 - Still support `.x, .y, .z, .w` for readability.
 - Compact, readable and easilly extendable.
 - All of the vector functions are available for all the vectors types
 and can be restricted to certain types. Also template specialization
 let us define exception for special class (like mpq).
 - With optimization ON, the compiler unroll the loops and performance
 is the same.

####Downsides:
 - Might impact debugability. Though I would arge that the bugs are
 rarelly caused by the vector class itself (since the operations are
 quite trivial) but by the type conversions.
 - Might impact compile time. I did not saw a significant impact since
 the usage is not really widespread.
 - Functions needs to be rewritten to support arbitrary vector length.
 For instance, one can't call `len_squared_v3v3` in
 `math::length_squared()` and call it a day.
 - Type cast does not work with the template version of the `math::`
 vector functions. Meaning you need to manually cast `float *` and
 `(float *)[3]` to `float3` for the function calls.
 i.e: `math::distance_squared(float3(nearest.co), positions[i]);`
 - Some parts might loose in readability:
 `float3::dot(v1.normalized(), v2.normalized())`
 becoming
 `math::dot(math::normalize(v1), math::normalize(v2))`
 But I propose, when appropriate, to use
 `using namespace blender::math;` on function local or file scope to
 increase readability.
 `dot(normalize(v1), normalize(v2))`

####Consideration:
 - Include back `.length()` method. It is quite handy and is more C++
 oriented.
 - I considered the GLM library as a candidate for replacement. It felt
 like too much for what we need and would be difficult to extend / modify
 to our needs.
 - I used Macros to reduce code in operators declaration and potential
 copy paste bugs. This could reduce debugability and could be reverted.
 - This touches `delaunay_2d.cc` and the intersection code. I would like
 to know @howardt opinion on the matter.
 - The `noexcept` on the copy constructor of `mpq(2|3)` is being removed.
 But according to @JacquesLucke it is not a real problem for now.

I would like to give a huge thanks to @JacquesLucke who helped during this
and pushed me to reduce the duplication further.

Reviewed By: brecht, sergey, JacquesLucke

Differential Revision: https://developer.blender.org/D13791
2022-01-12 12:47:43 +01:00
Clément Foucault e5766752d0 Revert "BLI: Refactor vector types & functions to use templates"
Reverted because the commit removes a lot of commits.

This reverts commit a2c1c368af.
2022-01-12 12:44:26 +01:00
Clément Foucault a2c1c368af BLI: Refactor vector types & functions to use templates
This patch implements the vector types (i.e:float2) by making heavy
usage of templating. All vector functions are now outside of the vector
classes (inside the blender::math namespace) and are not vector size
dependent for the most part.

In the ongoing effort to make shaders less GL centric, we are aiming
to share more code between GLSL and C++ to avoid code duplication.

Motivations:
- We are aiming to share UBO and SSBO structures between GLSL and C++.
  This means we will use many of the existing vector types and others we
  currently don't have (uintX, intX). All these variations were asking
  for many more code duplication.
- Deduplicate existing code which is duplicated for each vector size.
- We also want to share small functions. Which means that vector functions
  should be static and not in the class namespace.
- Reduce friction to use these types in new projects due to their
  incompleteness.
- The current state of the BLI_(float|double|mpq)(2|3|4).hh is a bit of a
  let down. Most clases are incomplete, out of sync with each others with
  different codestyles, and some functions that should be static are not
  (i.e: float3::reflect()).

Upsides:
- Still support .x, .y, .z, .w for readability.
- Compact, readable and easilly extendable.
- All of the vector functions are available for all the vectors types and
  can be restricted to certain types. Also template specialization let us
  define exception for special class (like mpq).
- With optimization ON, the compiler unroll the loops and performance is
  the same.

Downsides:
- Might impact debugability. Though I would arge that the bugs are rarelly
  caused by the vector class itself (since the operations are quite trivial)
  but by the type conversions.
- Might impact compile time. I did not saw a significant impact since the
  usage is not really widespread.
- Functions needs to be rewritten to support arbitrary vector length. For
  instance, one can't call len_squared_v3v3 in math::length_squared() and
  call it a day.
- Type cast does not work with the template version of the math:: vector
  functions. Meaning you need to manually cast float * and (float *)[3] to
  float3 for the function calls.
  i.e: math::distance_squared(float3(nearest.co), positions[i]);
- Some parts might loose in readability:
  float3::dot(v1.normalized(), v2.normalized())
  becoming
  math::dot(math::normalize(v1), math::normalize(v2))
  But I propose, when appropriate, to use
  using namespace blender::math; on function local or file scope to
  increase readability. dot(normalize(v1), normalize(v2))

Consideration:
- Include back .length() method. It is quite handy and is more C++
  oriented.
- I considered the GLM library as a candidate for replacement.
  It felt like too much for what we need and would be difficult to
  extend / modify to our needs.
- I used Macros to reduce code in operators declaration and potential
  copy paste bugs. This could reduce debugability and could be reverted.
- This touches delaunay_2d.cc and the intersection code. I would like to
  know @Howard Trickey (howardt) opinion on the matter.
- The noexcept on the copy constructor of mpq(2|3) is being removed.
  But according to @Jacques Lucke (JacquesLucke) it is not a real problem
  for now.

I would like to give a huge thanks to @Jacques Lucke (JacquesLucke) who
helped during this and pushed me to reduce the duplication further.

Reviewed By: brecht, sergey, JacquesLucke

Differential Revision: http://developer.blender.org/D13791
2022-01-12 12:19:39 +01:00
Campbell Barton 0dc309bef6 Cleanup: remove redundant const qualifiers for POD types 2022-01-12 12:51:11 +11:00
Campbell Barton 3d3bc74884 Cleanup: remove redundant const qualifiers for POD types
MSVC used to warn about const mismatch for arguments passed by value.
Remove these as newer versions of MSVC no longer show this warning.
2022-01-07 14:16:26 +11:00
Campbell Barton d6c3ea9e7a Cleanup: move public doc-strings into headers for 'blenfont'
Ref T92709
2021-12-08 17:12:35 +11:00
Brecht Van Lommel 7d5ef64bfb Cleanup: fix typos in comments and docs
Contributed by luzpaz.

Differential Revision: https://developer.blender.org/D13264
2021-11-19 12:46:49 +01: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
Campbell Barton 0654c41b0c Cleanup: use doxygen for BLF glyph
- Use doxy formatted functions.
- Use doxy sections.
2021-11-08 13:37:51 +11:00
Harley Acheson eddf5ad581 BLF: Refactor blf_glyph.c
Cleanup and Simplification of blf_glyph.c

See D13095 for details.

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

Reviewed by Campbell Barton
2021-11-06 11:29:48 -07:00
Campbell Barton 81baeec59b Cleanup: remove window_manager & editor includes from BLF
Remove the need to include the window manager & editor functions
in low level font rendering code.

- The default font size is now set when changed in the preferences.
- Flushing cache is set as a callback.
2021-11-06 16:28:02 +11:00
Julian Eisel 4e09fd76bc Cleanup (UI): Add/use type for operator context enum
Adds a `wmOperatorCallContext` typedef for the existing `WM_OP_XXX`
operator context enum. This adds type safety, allows the compiler to
produce better warnings and helps understanding what a variable is for.

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

Reviewed by: Campbell Barton
2021-11-05 14:57:26 +01: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 38fc19d643 Cleanup: rename blf_utf8_next_fast to blf_glyph_from_utf8_and_step
Calling this 'fast' no longer made sense as the slower code-path
has been removed.
2021-10-29 13:49:31 +11:00
Campbell Barton 1e2589bfa5 Cleanup: remove redundant BLI_UTF8_ERR check 2021-10-29 13:15:39 +11:00
Campbell Barton 0e71162e68 Cleanup: resolve cast warnings 2021-10-29 13:14:23 +11:00
Harley Acheson 70947ebc65 BLF Refactor: blf_utf8_next_fast
Simplification of BLF glyph loading

See D13026 for details.

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

Reviewed by Campbell Barton
2021-10-28 18:49:21 -07:00
Harley Acheson 59534dbee2 BLF Refactor: blf_kerning_step_fast
Simplification of BLF Kerning

See D13015 for more details.

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

Reviewed by Campbell Barton
2021-10-28 18:20:34 -07:00
Campbell Barton df8f507f41 Cleanup: spelling in comments 2021-10-06 14:54:05 +11:00
Campbell Barton 0b6be26126 BLF: remove checks for blend file relative paths
This was added in b24712a9ca
but is no longer needed as of efc129bc82.

Further, this wasn't reliable as it could fail on linked library data
which has a different base directory.

Assert when blend file relative paths are passed to BLF
(matching imbuf file loading).
2021-08-28 19:21:54 +10:00
Campbell Barton 89dae554f9 Cleanup: utf8 stepping functions
Various changes to reduce risk of out of bounds errors in utf8 seeking.

- Remove BLI_str_prev_char_utf8
  This function could potentially scan past the beginning of a string.
  Use BLI_str_find_prev_char_utf8 instead which takes a limiting
  string start argument.

- Swap arguments for BLI_str_find_prev_char_utf8 so the stepping
  argument is first and the limiting argument is last.
  This matches BLI_str_find_next_char_utf8.

- Change behavior of these functions to return it the start or end
  pointers instead of NULL, which complicated use of these functions
  to calculate offsets.

  Callers that need to check if the limits were reached can compare
  the return value with the start/end pointers.

- Return 'const char *' from these functions
  so they don't remove const from the input arguments.
2021-08-27 17:02:53 +10:00
Campbell Barton afcd06e1e1 Cleanup: spelling in comments 2021-08-26 12:36:58 +10:00
Harley Acheson 5b751c95f4 BLF: Remove ASCII-only Code Paths
Remove redundant code for drawing text strings that contain only ASCII.

See D12293 for much more detail.

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

Reviewed by Campbell Barton
2021-08-25 13:30:00 -07:00
Campbell Barton be906f44c6 BLI_string_utf8: simplify utf8 stepping logic
There were multiple utf8 functions which treated
errors slightly differently.

Split BLI_str_utf8_as_unicode_step into two functions.

- BLI_str_utf8_as_unicode_step_or_error returns error value
  when decoding fails and doesn't step.

- BLI_str_utf8_as_unicode_step always steps forward at least one
  returning the byte value without decoding
  (needed to display some latin1 file-paths).

Font drawing uses BLI_str_utf8_as_unicode_step and no longer
check for error values.
2021-08-25 15:27:18 +10:00
Campbell Barton 8b55cda048 Fix BLI_str_utf8_as_unicode_step reading past intended bounds
Add a string length argument to BLI_str_utf8_as_unicode_step to prevent
reading past the buffer bounds or the intended range since some callers
of this function take a string length to operate on part of the string.

Font drawing for example didn't respect the length argument,
potentially causing a buffer over-read with multi-byte characters
that could read past the end of the string.

The following command would read 5 bytes past the end of the input.

`BLF_draw(font_id, (char[]){252}, 1);`

In practice strings are typically null terminated so this didn't crash
reading past buffer bounds.

Nevertheless, this wasn't correct and could cause bugs in the future.

Clamping by the length now has the same behavior as a null byte.

Add test to ensure this is working as intended.
2021-08-24 14:25:15 +10:00
Campbell Barton 8371df8b1c Cleanup: spelling 2021-08-24 12:49:00 +10:00
Campbell Barton 62f2204d65 Cleanup: rename len to str_len for BLF functions
Make it obvious which variable this is the length of.
2021-08-23 15:08:28 +10:00
Campbell Barton 0b7947e855 Cleanup: minor changes to blf_font.c
- Use early return when kerning isn't used.
- Remove early return that prevented matching acquire/release calls.
2021-08-21 17:46:50 +10:00
Campbell Barton 47e68537f8 Cleanup: organize blf_font.c functions using doxy-sections
Functions in this file were scattered and not well organized.
2021-08-21 17:41:40 +10:00
Campbell Barton aed5a27755 Correct build error from 0d7aab2375 2021-08-21 13:22:47 +10: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
Campbell Barton 4db4123409 Correct assert from 22ab0159a9 2021-08-19 17:56:25 +10: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
Harley Acheson feaa61a968 UI: Remove "Unfitted" Kerning Style Option
This patch removes the "Kerning Style" option for UI widget font
drawing and uses only the current default of "Fitted", since the other
option of "Unfitted" is just the result of truncation errors.

see D12231 for much more information.

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

Reviewed by Campbell Barton
2021-08-18 19:48:30 -07:00
Campbell Barton c0016a8581 BLF: avoid unnecessary lookups in blf_kerning_cache_new
blf_kerning_cache_new was performing many unnecessary hash lookups,
calling blf_glyph_search 32768 times. Use a lookup table to reduce this
to the number of ASCII characters (128 calls).
2021-08-16 14:35:38 +10: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
Campbell Barton 87adcbc94f BLF: use fast ASCII kerning for word-wrap calculations
While this wasn't a bottleneck, using the fast version of this function
removes some duplicate code that doesn't use the look-up table.
2021-08-16 14:35:38 +10:00
Campbell Barton 6aebbe6a0a Cleanup: replace macros with inline functions for font drawing
Also assert blf_font_ensure_ascii_kerning has been called in
blf_kerning_step_fast.
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
Harley Acheson ae920d789e VSE: Allow Wingdings and Symbol Fonts
This patch makes us less restrictive on the allowed types of FreeType
font character maps we allow, rather than primarily unicode-only. This
allows us to use some legacy, symbol, specialty, and proprietary fonts
like Wingdings. Note we were a little less restrictive with vfonts,
used for 3D Text Objects, so this patch primarily helps VSE.

See D12124 for details and examples.

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

Reviewed by Brecht Van Lommel
2021-08-04 09:31:01 -07:00
Harley Acheson 8aa1c0a326 Fix T75028: Improved Font Names in File Manager
When viewing font files in the File Manager, this patch uses the font's
family and style names to show the same type of string shown to users
in operating system lists. For example "Book Antiqua Regular" instead
of "BKANT.ttf"

see D12020 for details and examples.

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

Reviewed by Campbell Barton and Julian Eisel
2021-07-28 11:16:04 -07:00
YimingWu b331acf477 Cleanup: comment spelling & punctuation 2021-07-27 18:06:29 +10:00
Campbell Barton 9b89de2571 Cleanup: consistent use of tags: NOTE/TODO/FIXME/XXX
Also use doxy style function reference `#` prefix chars when
referencing identifiers.
2021-07-04 00:43:40 +10:00
Campbell Barton f1e4903854 Cleanup: full sentences in comments, improve comment formatting 2021-06-26 21:50:48 +10:00
Campbell Barton 4b9ff3cd42 Cleanup: comment blocks, trailing space in comments 2021-06-24 15:59:34 +10:00
Germano Cavalcante 6e56b42faa Fix T77651: Black screen on Blender startup on ChromeOS
Apparently `textureSize` doesn't work with
`sampler1DArray` on this OS.

Thanks to @dave1853 for finding the source of the
problem.
2021-06-07 15:51:08 -03:00
Harley Acheson 875a8a6c79 Cleanup: Replace fseek() calls with BLI_fseek()
The fseek() function on Windows only accepts a 32-bit long offset
argument. Because of this we have our own version, BLI_fseek(), which
will use 64-bit _fseeki64() on Windows. This patch just replaces some
fseek() calls with BLI_fseek().

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

Reviewed by Brecht Van Lommel
2021-05-31 10:08:58 -07:00
Richard Antalik 6944521d7e Fix T87337: Text strip draws white outline
Math for drawing font over byte buffer was incorrect. Effect can be seen
when target buffer is fully black and transparent - this results in font
color being effectively premultiplied, which causes problems when image
is composited further.

Use `blend_color_mix_byte()` and `blend_color_mix_float()` for blending.

Reviewed By: sergey

Differential Revision: https://developer.blender.org/D11035
2021-04-22 08:16:16 +02:00
Germano Cavalcante 89c79c3ed8 Cleanup: Abbreviate enums with 'UNSIGNED_' in the name 2021-02-17 12:38:21 -03:00
Campbell Barton 20a6255d49 Cleanup: spelling 2021-02-17 15:04:29 +11:00
Campbell Barton 67c8d97db3 Cleanup: spelling 2021-02-14 20:58:04 +11:00
Bastien Montagne b24712a9ca Fix (studio-reported) broken handling of relative font paths.
`blf_dir_search` BLF util would not properly handle relative fonts not
found in pre-defined 'system fonts' directoriesi stored in
`global_font_dir` global variable.

Now it rebases relative paths to current .blend file location as
expected.

Note: the fact that VSE is setting font ptaths relative by default is
probably not actually desired, but this is another issue really. See
`BKE_sequencer_text_font_load` code.
2020-12-15 18:22:22 +01:00
Campbell Barton 4d3a386af2 Cleanup: spelling 2020-10-26 15:59:08 +11:00
Campbell Barton 36653a92fa Cleanup: centralize BLF default functions in the header 2020-10-22 17:30:52 +11:00
Campbell Barton cf5ae6718c Cleanup: split BLF default into own file
This avoids accidents using user-preferences in the main BLF API,
which could cause preferences to be used unintentionally
(such as stamping into renders or creating generated images).

As well as uses of BLF when preferences aren't loaded
such as animation playback.
2020-10-22 17:24:19 +11:00
Harley Acheson 4bf6ffc022 Fix for T81757: Incorrect Overlay Line Height
Fixes error in determining 3DView Overlay Line Height. Do not base on current default font height.

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

Reviewed by Campbell Barton
2020-10-20 19:11:36 -07:00
Harley Acheson 19dcd32ee5 UI: Remove Hard-coded Default Font Size
Default text output routines (which do not specify a size) will now use Text Style point size.

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

Reviewed by Brecht Van Lommel
2020-10-12 09:53:00 -07:00
Clément Foucault c68a2a722d Fix T80599 Blender Cloud folder text on the screen very small
This was caused by BLF conflicting with BGL api change.
2020-10-12 15:33:01 +02:00
Clément Foucault 6432fa488a Cleanup: Remove GLEW dependencies outside of GL module 2020-09-12 15:51:21 +02:00
Jacques Lucke ddf4f28968 Cleanup: reduce variable scope 2020-09-09 15:43:27 +02:00
Clément Foucault 6b436b80a4 GPU: Rename gpu_extensions to gpu_capabilities
This makes more sense as this module has more to it than just
GL extensions.
2020-09-07 19:37:05 +02:00
Clément Foucault ab95cdaba9 GPUTexture: Change texture creation API
This is to modernize the API:
- Add meaningful name to all textures (except DRW textures).
- Remove unused err_out argument: only used for offscreen python.
- Add mipmap count to creation functions for future changes.
- Clarify the data usage in creation functions.

This is a cleanup commit, there is no functional change.

# Conflicts:
#	source/blender/gpu/GPU_texture.h
2020-09-05 17:49:14 +02:00
Clément Foucault bac4606937 Cleanup: GPUTexture: Remove use of GPU_texture_create_nD
Use creation + update function instead.
2020-09-05 17:49:14 +02:00
Clément Foucault f72c1c4547 GPUTexture: Remove bind to edit calls
This is going to be unecessary after the GPU opengl texture backend refactor.

For now add a save/restore mechanism to leave the state untouched.

Also remove some calls where the caller would bind to particular binding
point and set the shader uniform.
2020-09-05 17:49:14 +02:00
Clément Foucault 298329554a Cleanup: GPUState: remove double GPU_blend calls 2020-08-18 21:30:10 +02:00
Clément Foucault bf1b622dd9 GPUState: GPU_blend final API renaming
We now use GPU_blend for enabling / disabling blending and explicitly
set the blend equation.
2020-08-18 21:30:10 +02:00
Clément Foucault 969bcf0793 Cleanup: GPUState: Replace blend func separate by enum 2020-08-18 21:30:10 +02:00
Clément Foucault ac60a67b3f Cleanup: GPU: Remove Batch vao cache reset
This is done at drawtime automatically.
2020-08-13 14:20:24 +02:00
Campbell Barton b134434224 Cleanup: declare arrays arrays where possible 2020-08-07 22:37:39 +10:00
Jacques Lucke 7283e6fb73 Merge branch 'blender-v2.90-release' into master 2020-08-07 10:04:57 +02: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
Clément Foucault 025dc31d28 GPU: Remove GL constant from BIF_glutil 2020-07-26 21:07:25 +02:00
Sergey Sharybin cad2d32be6 Clang-Tidy: Enable bugprone-misplaced-widening-cast 2020-07-03 17:10:27 +02:00
Harley Acheson a39cc5ae4d Fix for T77478: Quiet Conversion Error/Warning
Quiet warning/error about int and float multiplication.

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

Reviewed by Ray Molenkamp
2020-06-05 17:05:06 -07: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 a6380d063f Cleanup: store BLF buffer size in a variable 2020-05-03 18:10:25 +10: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
Campbell Barton 0d65520f05 BLF: add new arguments to BLF_GlyphBoundsFn
- glyph_bounds: to get the character width.
- glyph_bearing: lower left character starting point.

These values are needed for more precise glyph calculations.
2020-05-03 16:51:34 +10:00
Campbell Barton e78470d954 BLF: add utility function to loop over glyph bounds 2020-04-28 13:34:56 +10:00
Campbell Barton 973e1f9d9a Cleanup: use term 'attr' instead of 'attrib'
This was already the case in most parts of the GPU API.
Use full name for descriptive-comments.
2020-04-03 17:25:58 +11:00
Brecht Van Lommel 68e341e9d5 UI: remove non-unicode font and simplify default font loading code
There is no need to have another font embedded in the Blender executable, we
can assume the bundled font exists. In the future we may provide a fallback
if the font specified by the user in the preferences is missing a character,
but that can use our bundled international font.

Differential Revision: https://developer.blender.org/D6854
2020-03-25 16:39:58 +01:00
Brecht Van Lommel 9070999c21 UI: always use international font
This means Blender can display more text correctly without having to enable
user interface translation. Previously the quality of the font was lower,
but that has been fixed now.

The font files have now been ungzipped, which results in faster file loading
as Freetype can read only the parts of the file that it needs. Blender download
size should not increase since the release package is compressed.

This includes improvements for Cyrillic characters from the latest DejaVu
Sans fonts from D6960, contributed by Harley Acheson. Fixes T74097.

Differential Revision: https://developer.blender.org/D6854
2020-03-25 16:39:37 +01:00
Dalai Felinto 2d1cce8331 Cleanup: `make format` after SortedIncludes change 2020-03-19 09:33:58 +01:00
Campbell Barton 4184f890fd GPU: minor changes to support standalone GHOST builds
- Move gpuPush/Pop from GPU_draw.h into GPU_state.h
  as this is for pushing/popping state.
- Add 'GPU_STANDALONE' define, to bypass use of user-preferences
  for theme colors and pixelsize, as well as pbvh init/free functions.

Needed to get GHOST tests working again.
2020-03-11 14:52:57 +11:00
Jacques Lucke 51bce18b6f Cleanup: make blf header work in C++ 2020-03-02 15:34:17 +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
mano-wii 0feb03e680 Fix T73763: Laggy when zooming a node editor with International Fonts
Two main reasons for the lag:
- Allocation of memory with transfer to GPU.
- BLF_cache_clear();

The (partial) solution is to avoid memory allocating in some setups
through the `GPU_texture_clear`.

Differential Revision: https://developer.blender.org/D6837
2020-02-15 12:18:52 -03:00
Clément Foucault 12728d43f8 Revert "Fix T73763: Laggy with nodes Editor + International Fonts"
This reverts commit a21f5ec562.
2020-02-15 00:22:56 +01:00
mano-wii a21f5ec562 Fix T73763: Laggy with nodes Editor + International Fonts
Two main reasons for the lag:
- Allocation of memory with transfer to GPU.
- BLF_cache_clear();

The memory allocation seems to be unnecessary, so I removed it.

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D6837
2020-02-14 11:25:41 -03:00
Sergey Sharybin 6fff73e3f0 Merge branch 'blender-v2.82-release' 2020-01-23 16:59:50 +01:00
Sergey Sharybin 517870a4a1 CMake: Refactor external dependencies handling
This is a more correct fix to the issue Brecht was fixing in D6600.

While the fix in that patch worked fine for linking it broke ASAN
runtime under some circumstances.
For example, `make full debug developer` would compile, but trying
to start blender will cause assert failure in ASAN (related on check
that ASAN is not running already).

Top-level idea: leave it to CMake to keep track of dependency graph.

The root of the issue comes to the fact that target like "blender" is
configured to use a lot of static libraries coming from Blender sources
and to use external static libraries. There is nothing which ensures
order between blender's and external libraries. Only order of blender
libraries is guaranteed.

It was possible that due to a cycle or other circumstances some of
blender libraries would have been passed to linker after libraries
it uses, causing linker errors.

For example, this order will likely fail:

  libbf_blenfont.a libfreetype6.a libbf_blenfont.a

This change makes it so blender libraries are explicitly provided
their dependencies to an external libraries, which allows CMake to
ensure they are always linked against them.

General rule here: if bf_foo depends on an external library it is
to be provided to LIBS for bf_foo.
For example, if bf_blenkernel depends on opensubdiv then LIBS in
blenkernel's CMakeLists.txt is to include OPENSUBDIB_LIBRARIES.

The change is made based on searching for used include folders
such as OPENSUBDIV_INCLUDE_DIRS and adding corresponding libraries
to LIBS ion that CMakeLists.txt. Transitive dependencies are not
simplified by this approach, but I am not aware of any downside of
this: CMake should be smart enough to simplify them on its side.
And even if not, this shouldn't affect linking time.

Benefit of not relying on transitive dependencies is that build
system is more robust towards future changes. For example, if
bf_intern_opensubiv is no longer depends on OPENSUBDIV_LIBRARIES
and all such code is moved to bf_blenkernel this will not break
linking.

The not-so-trivial part is change to blender_add_lib (and its
version in Cycles). The complexity is caused by libraries being
provided as a single list argument which doesn't allow to use
different release and debug libraries on Windows. The idea is:

- Have every library prefixed as "optimized" or "debug" if
  separation is needed (non-prefixed libraries will be considered
  "generic").

- Loop through libraries passed to function and do simple parsing
  which will look for "optimized" and "debug" words and specify
  following library to corresponding category.

This isn't something particularly great. Alternative would be to
use target_link_libraries() directly, which sounds like more code
but which is more explicit and allows to have more flexibility
and control comparing to wrapper approach.

Tested the following configurations on Linux, macOS and Windows:

- make full debug developer
- make full release developer
- make lite debug developer
- make lite release developer

NOTE: Linux libraries needs to be compiled with D6641 applied,
otherwise, depending on configuration, it's possible to run into
duplicated zlib symbols error.

Differential Revision: https://developer.blender.org/D6642
2020-01-23 16:59:18 +01:00
James Fulop 482f3c008b Cleanup: use existing helper for float to uchar color conversion
Differential Revision: https://developer.blender.org/D6617
2020-01-20 14:52:38 +01:00
Lukas Stockner c30d6571bb Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.

With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.

The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.

The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles

There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images

Thanks to Brecht for the review and to all who tested the intermediate versions!

Differential Revision: https://developer.blender.org/D3509
2019-12-12 18:40:37 +01:00
Clément Foucault 9516921c05 Overlay Engine: Refactor & Cleanup
This is the unification of all overlays into one overlay engine as described in T65347.

I went over all the code making it more future proof with less hacks and removing old / not relevent parts.

Goals / Acheivements:
- Remove internal shader usage (only drw shaders)
- Remove viewportSize and viewportSizeInv and put them in gloabl ubo
- Fixed some drawing issues: Missing probe option and Missing Alt+B clipping of some shader
- Remove old (legacy) shaders dependancy (not using view UBO).
- Less shader variation (less compilation time at first load and less patching needed for vulkan)
- removed some geom shaders when I could
- Remove static e_data (except shaders storage where it is OK)
- Clear the way to fix some anoying limitations (dithered transparency, background image compositing etc...)
- Wireframe drawing now uses the same batching capabilities as workbench & eevee (indirect drawing).
- Reduced complexity, removed ~3000 Lines of code in draw (also removed a lot of unused shader in GPU).
- Post AA to avoid complexity and cost of MSAA.

Remaining issues:
- ~~Armature edits, overlay toggles, (... others?) are not refreshing viewport after AA is complete~~
- FXAA is not the best for wires, maybe investigate SMAA
- Maybe do something more temporally stable for AA.
- ~~Paint overlays are not working with AA.~~
- ~~infront objects are difficult to select.~~
- ~~the infront wires sometimes goes through they solid counterpart (missing clear maybe?) (toggle overlays on-off when using infront+wireframe overlay in solid shading)~~

Note: I made some decision to change slightly the appearance of some objects to simplify their drawing. Namely the empty arrows end (which is now hollow/wire) and distance points of the cameras/spots being done by lines.

Reviewed By: jbakker

Differential Revision: https://developer.blender.org/D6296
2019-12-02 13:15:52 +01:00
mano-wii 177dfc6384 Fix T71273: Bad encoding of utf-8 for Text objects
`BLI_strncpy_wchar_from_utf8` internally assumes `wchar_t` is 32 bits
which is not the case on windows.

The solution is to replace `wchar_t` with `char32_t`.

Thanks to @robbott for compatibility on macOS.

Differential Revision: https://developer.blender.org/D6198
2019-11-22 12:27:34 -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
Brecht Van Lommel 6b0d1ef7e1 Cleanup: compiler warnings 2019-09-13 16:51:51 +02:00
Campbell Barton 0ec6564668 Cleanup: unused headers (GPU) 2019-09-14 00:22:24 +10:00
Campbell Barton ac646bc20d Cleanup: spelling 2019-08-31 01:21:42 +10:00
Campbell Barton 03b2371387 Cleanup: move trailing comments to avoid wrapping code
Some statements were split across multiple lines because of their
trailing comments.

In most cases it's clearer to put the comments above.
2019-08-14 23:32:24 +10:00
Bastien Montagne 3b6c75dc31 Fix T67620: Font preview translations malfunction in Blender 2.8
We cannot reliably use translations API from non-main threads.

Now storing translated strings in a static cache, with basic mechanism
to update it on language change.

Reviewers: brecht, campbellbarton

Differential Revision: https://developer.blender.org/D5350
2019-07-29 14:11:35 +02:00
Sebastian Parborg 52fb8b1e80 Fix T67117: Font thumbnails crash to desktop
We were missing a null pointer check for invalid fonts.
2019-07-24 11:26:21 +02:00
Campbell Barton db4804690b BLF: pass code-point to BLF_has_glyph
Avoid BLF having to be concerned with decoding the string
(which can fail).

Also remove redundant extra zero byte from strings.
2019-05-02 10:52:53 +10:00
Harley Acheson 3747282932 UI: use Mac key symbols in menus on macOS, instead of text like "Cmd"
On Windows "Cmd" is also replaced with "Win".

Differential Revision: https://developer.blender.org/D4689
2019-05-01 18:05:01 +02:00
Campbell Barton f9ee08610a Cleanup: comments (long lines) in misc libraries 2019-04-29 22:06:26 +10:00
Campbell Barton 2753959ed7 Cleanup: sort CMake include paths 2019-04-24 14:41:12 +10:00
Campbell Barton 67454a282d Cleanup: style, use braces for blenfont 2019-04-22 19:48:16 +10:00
Campbell Barton 380ce86a7f Cleanup: comments (long lines) in avi, blf & blt 2019-04-22 06:30:08 +10: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 5498e7f193 CMake: add library deps to CMakeLists.txt
Tested to work on Linux and macOS.

This will be enabled once all platforms are verified.

See D4684
2019-04-16 06:20:52 +02:00
Campbell Barton 47adab4f99 CMake: prepare for BLENDER_SORTED_LIBS removal
No functional change, this adds LIB definition and args to cmake files.
Without this it's difficult to migrate away from 'BLENDER_SORTED_LIBS'
since there are many platforms/configurations that could break when
changing linking order.

Manually add and enable WITHOUT_SORTED_LIBS to try building
without sorted libs (currently fails since all variables are empty).
This check will eventually be removed.

See T46725.
2019-04-14 15:37:24 +02:00
Campbell Barton eff8cc9ccc Cleanup: doxy comments
Use doxy references to function and enums,
also correct some names which became out of sync.
2019-04-14 10:48:42 +02:00
Sebastian Parborg b2656a6ee4 Fix T62887: When searching for fonts, thumbnail display mode will crash Blender
We do not support special color fonts (like colored emoji fonts), so
don't crash when trying to create a preview for unsupported fonts.

Reviewed By: Brecht

Differential Revision: http://developer.blender.org/D4590
2019-03-26 14:11:35 +01:00
Jacques Lucke 1b1b604596 Fix T62678: better glyph clipping test
Reviewers: billreynish, brecht

Differential Revision: https://developer.blender.org/D4550
2019-03-20 13:33:52 +01:00
Campbell Barton e7fd6c8f30 Cleanup: comment blocks 2019-03-19 15:17:46 +11:00
Jacques Lucke cfd909f184 Fix T62678: Wrong text clipping
There are two issues at play here.
First, BLF_width computed a width that was not wide
enough to actually hold the text.
Second, blf_glyph_calc_rect_test computed an incorrect
rect->xmax when the glyph was moved to the left a bit.
We ignore the overlap on the left, but the right side
should still be adjusted accordingly.
2019-03-17 14:15:26 +01:00
Jacques Lucke 7bfdf35711 Fix T61300: First letter truncated
The main problem was that the character `J` has "negative kerning".
It was cut off because it started outside of the clipping rectangle.

Reviewers: brecht

Differential Revision: https://developer.blender.org/D4513
2019-03-14 15:45:21 +01: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 ab5e69e660 Cleanup: remove contributors for CMake files
Following removal from C source code.

See: 8c68ed6df1
2019-02-05 09:10:32 +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
Campbell Barton c0f88ed8a8 Cleanup: sort forward declarations of enum & struct
Done using:
  source/tools/utils_maintenance/c_sort_blocks.py
2019-01-28 21:17:58 +11:00
Campbell Barton 04a5dbbd09 Correct build error removing includes 2019-01-26 23:08:11 +11:00
Campbell Barton 1e4aab36c2 Cleanup: remove redundant BKE/BLI/BIF headers 2019-01-26 21:20:25 +11:00
Campbell Barton 2e4f1b592f Cleanup: use eGPU prefix for GPU enum types 2019-01-23 14:16:03 +11:00
Sergey Sharybin 362331f0ff Cleanup: Remove unused variable 2019-01-22 12:02:35 +01:00
Campbell Barton 88218946da Cleanup: minor changes to reduce code duplication
D4236 by @sobakasu w/ edits.
2019-01-22 13:51:21 +11:00
Campbell Barton b4aec52007 Cleanup: de-duplicate font loading code
Part of D4236 by @sobakasu
2019-01-22 13:11:31 +11:00
Campbell Barton dd3f518626 Cleanup: rename GPU function to set buffer length 2019-01-21 11:28:41 +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
Campbell Barton e305560f13 Cleanup: add trailing commas to structs
Needed for clang formatting to workaround bug/limit, see: T53211
2019-01-07 00:34:48 +11:00
Bastien Montagne 1ac311cedc Fix/cleanup another bunch of UI messages issues.
Also (mostly in comments): behaviour -> behavior (we use American English).
2018-12-24 12:32:43 +01:00
Bastien Montagne 1158b9f73a Cleanup: First batch of UI messages fixes (typos, final points...).
Also contains some code typo fixes (mostly, adtaptative -> adaptive,
former is nearly innexistant in English, let's stick to simple valid
words ;) ).
2018-12-23 22:03:43 +01:00
Jacques Lucke 21744217ce Cleanup: remove some #if 0 blocks
Reviewers: brecht, campbellbarton

Differential Revision: https://developer.blender.org/D3802
2018-10-17 12:43:41 +02:00
Bastien Montagne fb60fb055d Improvements to internals blf_font's `blf_font_width_to_strlen()`/`to_rstrlen()`
`to_strlen` just benefits from using pre-computed kerning table for
ascii chars (gives about 30% speed improvements).

`to_rstrlen` was re-written and heavily simplified, basically using same
logic as `to_strlen`, and `BLI_str_find_prev_char_utf8()` to loop
backward in the string, instead of looping forwards the whole string,
storing each gliph's width in temp array, and looping backward on that
temp array to find final string matching expected width. Gives about 70%
speed improvements!

And both functions can now share their core logic.
2018-10-03 16:24:35 +02:00
Brecht Van Lommel 596c3368f4 Merge branch 'master' into blender2.8 2018-08-21 19:08:23 +02:00
Brecht Van Lommel 34029fc71a UI: disable new text hinting from D3201 by default for now.
This changes the text hinting setting to be an enum with options
Auto / None / Slight / Full. The default is Auto which currently disables
hinting.

The hinting was tested with a new FreeType version, but this is not what
is used on the buildbots an official release environment, and the fonts
look quite bad because of that. Once FreeType has been upgraded we can
change the default.

Even then the results are not ideal, perhaps due to missing subpixel
positioning and linear color blending support in BLF.
2018-08-21 19:07:04 +02:00
Brecht Van Lommel 1d067868c0 UI: tweak drawing of header status text for transparent headers. 2018-08-15 16:00:40 +02:00
Campbell Barton 5300ba0ba5 Merge branch 'master' into blender2.8 2018-07-31 17:03:28 +10:00
Campbell Barton 21f61cbe73 BLF: replace global aa pref w/ monochrome flag
Now disabling anti-aliasing doesn't impact sequencer, render stamp etc.
2018-07-31 16:57:05 +10:00
Brecht Van Lommel 17c3110ae5 Fix large font drawing blurriness in a better way.
GPU_LINEAR is there for shadow font blurring, the real issue was lack of
rounding for the batch offset.
2018-07-23 16:16:39 +02:00