Commit graph

61 commits

Author SHA1 Message Date
Luca Bacci
ee554c8610 DWrite: Fix switch for grid-fit mode
Ooops!
2025-06-16 17:52:15 +02:00
Luca Bacci
4d141f08fb DWrite: Add fallback for OS versions up to Windows 8
IDWriteGlyphRunAnalysis supports gray-scale antialiasing only when
created via IDWriteFactory2 (and newer), introduced in Windows 8.1

Fallback to using DIrect2D on A8 targets when IDWriteFactory2 is
not available.
2025-02-10 17:18:46 +01:00
Luca Bacci
78fca779ba DWrite: Get glyph coverage using IDWriteGlyphRunAnalysis 2025-02-10 17:18:40 +01:00
Emmanuele Bassi
fe87f1c3fb Merge branch 'win32-cleanup' into 'master'
Win32 cleanup

See merge request cairo/cairo!605
2025-01-30 09:29:01 +00:00
Emmanuele Bassi
e2a52c0870 Merge branch 'dwrite-font-variations' into 'master'
DWrite: Add support for font variations

Closes #877

See merge request cairo/cairo!601
2025-01-30 09:26:49 +00:00
Luca Bacci
e0287e09f4 DWrite/GeometryRecorder: Add final specifier 2025-01-21 13:55:27 +01:00
Luca Bacci
46153a0408 DWrite/GeometryRecorder: Complete implementation of QueryInterface
...by checking for IUnknown.

This makes GeometryRecorder::QueryInterface compliant with the
rules of COM.

QueryInterface for IUnknown has a special meaning in COM: it's
used to check whether two interface pointers refer to the same
object.
2025-01-21 13:55:26 +01:00
Luca Bacci
59197e7791 DWrite/GeometryRecorder: Add noexcept specifier
STDMETHOD / IFACEMETHOD macros already add __declspec(nothrow), but
noexcept is better. From MSDN [1]:

  We recommend that all new code use the noexcept operator rather than
  __declspec(nothrow).
  This attribute tells the compiler that the declared function and the
  functions it calls never throw an exception. However, it does not
  enforce the directive. In other words, it never causes std::terminate
  to be invoked, unlike noexcept, or in std:c++17 mode (Visual Studio
  2017 version 15.5 and later), throw().

See also [2]:

  Non-throwing functions are permitted to call potentially-throwing
  functions. Whenever an exception is thrown and the search for a handler
  encounters the outermost block of a non-throwing function, the function
  std::terminate is called:

  extern void f(); // potentially-throwing

  void g() noexcept {
    f();      // valid, even if f throws
    throw 42; // valid, effectively a call to std::terminate
  }

References:

 [1] https://learn.microsoft.com/en-us/cpp/cpp/nothrow-cpp?view=msvc-170
 [2] https://en.cppreference.com/w/cpp/language/noexcept_spec
2025-01-21 13:55:19 +01:00
Luca Bacci
8107086c6a DWrite/GeometryRecorder: Add override specifier
IFACEMETHOD already adds the __override / __allowed(on_function) SAL
annotation (only on Windows SDK, not mingw-w64), which is understood
by some code analysis tools [1]. Since we're compiling in C++11 mode,
we can add the override specifier, so that the compiler is informed
as well.

[1] https://devblogs.microsoft.com/oldnewthing/20200911-00/?p=104205
2025-01-21 12:16:35 +01:00
Luca Bacci
bdac729974 DWrite/GeometryRecorder: Use IFACEMETHOD consistently
Fixes the following warnings on CLang:

  ../cairo/src/win32/cairo-dwrite-font.cpp:869:27: warning: exception specification
  of overriding function is more lax than base version [-Wmicrosoft-exception-spec]
    869 |     IFACEMETHODIMP_(void) SetFillMode(D2D1_FILL_MODE fillMode)
        |                           ^
  D:/msys64/clang64/include/d2d1.h:1491:22: note: overridden virtual function is here
   1491 |     STDMETHOD_(void, SetFillMode)(D2D1_FILL_MODE fillMode) PURE;
        |

COM objects are usually implemented like that:

1. The class is defined with only method declarations. For that,
   one should use IFACEMETHOD macros.
2. Then methods are implemented (defined), outside of the class
   definition. For that, one should use the IFACEMETHODIMP macros

If one really wants to provide inline method definitions (that is,
inside the class definition), then IFACEMETHOD macros should be used
(and not IFACEMETHODIMP, though it's a definition / implementation).
2025-01-21 12:02:51 +01:00
Luca Bacci
864ede8e1a Win32: Load system DLLs from System32 2025-01-21 11:59:09 +01:00
Luca Bacci
e10adb1c2b Win32: Pass FORMAT_MESSAGE_IGNORE_INSERTS
This should always be passed when retreving messages from third
parties (unless the third party documents format strings)

See https://devblogs.microsoft.com/oldnewthing/20071128-00/?p=24353
2025-01-16 16:49:05 +01:00
Luca Bacci
56b8933ede DWrite: Remove unused variables 2025-01-08 11:06:26 +01:00
Luca Bacci
b84b3542d1 DWrite: Add support for font variations
Fixes https://gitlab.freedesktop.org/cairo/cairo/-/issues/877
2024-11-11 19:41:07 +01:00
Luca Bacci
6cd0a7d395 DWrite: Add IDWriteFontFace field in the scaled font subclass
...and make the code use that instead of the original IDWriteFontFace
in the font face subclass. We do that because to apply a few settings
(font variations) a new IDWriteFontFace must be created out of the
original one.

For now the IDWriteFontFace in the scaled font is a copy of the one in
the font face. In the next commit we'll add code to create a different
object.
2024-11-08 17:00:45 +01:00
Nirbheek Chauhan
0835add95c dwrite: Fix build with MinGW 11
DWRITE_GLYPH_IMAGE_FORMATS is now defined by dcommon.h

In file included from C:/msys64/ucrt64/include/minwindef.h:163,
                 from C:/msys64/ucrt64/include/windef.h:9,
                 from C:/msys64/ucrt64/include/windows.h:69,
                 from ..\src/cairo-mutex-impl-private.h:182,
                 from ..\src/cairo-mutex-type-private.h:45,
                 from ..\src/cairo-scaled-font-private.h:45,
                 from ..\src/cairoint.h:415,
                 from ../src/win32/cairo-dwrite-font.cpp:37:
../src/win32/dw-extra.h:26:1: error: redefinition of 'DWRITE_GLYPH_IMAGE_FORMATS operator|(DWRITE_GLYPH_IMAGE_FORMATS, DWRITE_GLYPH_IMAGE_FORMATS)'
   26 | DEFINE_ENUM_FLAG_OPERATORS(DWRITE_GLYPH_IMAGE_FORMATS);
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~
C:/msys64/ucrt64/include/dcommon.h:67:1: note: 'DWRITE_GLYPH_IMAGE_FORMATS operator|(DWRITE_GLYPH_IMAGE_FORMATS, DWRITE_GLYPH_IMAGE_FORMATS)' previously defined here
   67 | DEFINE_ENUM_FLAG_OPERATORS(DWRITE_GLYPH_IMAGE_FORMATS)
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~
2024-10-18 04:33:55 +05:30
Adrian Johnson
0cae2a4a74 Use _cairo_calloc() to allocate structs
To avoid any possibility of uninitialized memory.

The exceptions are:
 - where the allocation is immediately overwritten by a memcpy or struct copy.
 - arrays of structs to avoid any performance impact (except when the
   array is returned by the public API).
2024-06-21 10:32:23 +09:30
Fujii Hironori
1b62ef3e55 DWrite: region clipping didn't work on win32 surfaces
The following clipping text tests of win32/rgb24 target were visibly
failing because clipping didn't work.

* clip-text
* partial-clip-text-bottom
* partial-clip-text-left
* partial-clip-text-right
* partial-clip-text-top

_cairo_win32_gdi_compositor_glyphs sets the clip. However,
_cairo_dwrite_show_glyphs_on_surface unset it.

Fixes cairo/cairo#641
2023-03-01 13:55:20 +09:00
Fujii Hironori
c33383b10d DWrite: Support antialias and subpixel order font options
Create a new IDWriteRenderingParams object from the given font
options.
2023-02-27 11:55:30 +09:00
Fujii Hironori
950e3fb45d Change the workaround of MinGW dwrite_3.h problem
The DWRITE_COLOR_GLYPH_RUN1 struct definition of the old MinGW
dwrite_3.h was invalid. To work around the problem, dw-extra.h defined
the correct struct definition and all necessary API from dwrite_3.h.
This approach needed to redefine all necessary API.

This change added DWRITE_COLOR_GLYPH_RUN1_WORKAROUND struct and use it
for IDWriteColorGlyphRunEnumerator1::GetCurrentRun.
2023-02-27 11:55:30 +09:00
Fujii Hironori
5ae029c2cc DWrite: Inflate glyph bounds 1px vertically too
The most top and bottom lines of glyphs were clipped in some fonts and
conditions. The glyph bounds were inflated 1px horizontally. It should
inflate vertically too.

Fixes cairo/cairo#569
2023-02-20 14:16:30 +09:00
Adrian Johnson
b7d8da7d1f Merge branch 'issue-641-glyph-bounds' into 'master'
DWrite: clipped glyphs in win32 compositor

Closes #641

See merge request cairo/cairo!459
2023-02-16 10:14:07 +00:00
Fujii Hironori
cce89abbb9 DWrite: clipped glyphs in win32 compositor
The win32 compositor is using _cairo_dwrite_show_glyphs_on_surface for
DWrite. It was assuming that a glyph was painted inside 3x3 of the em
square. It should take the actual glyph bounding box by using
GetAlphaTextureBounds.

Fixes cairo/cairo#641
2023-02-14 05:29:47 +09:00
Fujii Hironori
adcd1e7325 DWrite: glyph surfaces should take subpixel positions into account
Shift the glyph position by phases taken
by _cairo_scaled_glyph_xphase and _cairo_scaled_glyph_yphase.

Fixes #597
2023-02-10 10:05:57 +09:00
Fujii Hironori
1d8032c406 DWrite: Don't convert subpixel antialiasing to grayscale
Reuse the win32 font code to create a glyph mask for a dwrite font.
Renamed a function _compute_mask in cairo-win32-font.c to
_cairo_compute_glyph_mask.
2023-02-09 13:19:36 +09:00
Adrian Johnson
cae2376dd0 Merge branch 'doc-fixes' into 'master'
More random doc fixes

See merge request cairo/cairo!437
2023-02-08 09:53:29 +00:00
Fujii Hironori
db4c941c34 DWrite: More accurate glyph paths for small fonts
Applying a transformation matrix to a glyph path after converting
floats to fixed point numbers caused caluculation errors. Apply the
transform before the conversion.

Fixes cairo/cairo#611
2023-02-08 05:41:07 +09:00
Khaled Hosny
eaf8859877 doc: Fix dwrite gtk-doc warnings
Don’t use gtk-doc comment syntax for regular comments.
2023-02-02 14:13:56 +02:00
Fujii Hironori
44e11a96a6 DWrite: Fix incorrect glyph metrics for negative glyph height
GetGdiCompatibleMetrics may return a glyph metrics that yields a small
nagative glyph height. But, it was calculated in unsigned integer.
And, it resulted in a very large glyph metrics.

Calculate glyph width and height in signed integer and let them
non-negative.
2023-02-02 05:27:18 +09:00
Fujii Hironori
bbc6cdb4ef DWrite: Added new API to set measuring mode and rendering params
Added the following API:
* cairo_dwrite_font_face_get_measuring_mode
* cairo_dwrite_font_face_get_rendering_params
* cairo_dwrite_font_face_set_measuring_mode
* cairo_dwrite_font_face_set_rendering_params
2023-02-02 05:27:18 +09:00
Fujii Hironori
cb3410b69f DWrite: Removed old unused API
Removed the following functions:
* cairo_dwrite_get_cleartype_rendering_mode
* cairo_dwrite_set_cleartype_params
* cairo_dwrite_scaled_font_get_force_GDI_classic
* cairo_dwrite_scaled_font_set_force_GDI_classic
2023-02-02 05:27:18 +09:00
Adrian Johnson
775017ee0d Merge branch 'dwrite-cpp-header' into 'master'
Add cairo-dwrite.h header file

See merge request cairo/cairo!425
2023-02-01 08:21:12 +00:00
Adrian Johnson
1585587668 dwrite: create C++ dwrite header 2023-01-31 06:54:32 +10:30
Adrian Johnson
e8cac307e1 Fix dwrite crash when printing dwrite toy font
Fixes #632
2023-01-30 07:19:03 +10:30
Adrian Johnson
407bb0a478 Merge branch 'dwrite-custom-palette' into 'master'
dwrite: use custom palette when rendering COLRv0

See merge request cairo/cairo!424
2023-01-27 10:44:31 +00:00
Adrian Johnson
119ce21b2c Merge branch 'dwrite-docs' into 'master'
Simplify generating dwrite-fonts docs

See merge request cairo/cairo!426
2023-01-27 10:16:55 +00:00
Khaled Hosny
0cc13eb894 Simplify generating dwrite-fonts docs
Tell gtk-doc to scan .cpp files instead of making a proxy .c file.
2023-01-26 13:08:45 +02:00
Adrian Johnson
e93d175aac Add new cairo_user_scaled_font_get_foreground_source() function
The previous approach using foreground colors in user fonts does not
work for gradients since the foreground color is not available at the
time of recording.

Add a new function cairo_user_scaled_font_get_foreground_source() that
can be called by the color render function to retrieve the foreground
pattern. Calling this function signals to cairo that the foreground
color is used. In this case cairo will call the render function
whenever the foreground color has changed.
2023-01-26 19:49:06 +10:30
Adrian Johnson
75d876ee29 dwrite: use custom palette when rendering COLRv0 2023-01-26 13:19:53 +10:30
Behdad Esfahbod
8fbfb7f377 [scaled-font] Clean up font-options before copy 2023-01-19 13:42:23 -07:00
Fujii Hironori
a599720c88 DWrite: Don't call _controlfp_s with MCW_PC
GeometryRecorder class was calling _controlfp_s with MCW_PC to reset
the floating point precision to default. However, MCW_PC isn't
supported for ARM or x64 platforms. It reports an assertion failure
for them. And, Cairo isn't changing the MCW_PC setting. Removed the
calls. Also, removed `GetFixedX` and `GetFixedY` methods because they
called only `_cairo_fixed_from_double`.

Fixes cairo/cairo#566
2023-01-11 05:39:13 +09:00
Luca Bacci
8266d2d5f2 Pair usage of operator new[] with a corresponding delete[] 2022-09-03 14:16:04 +02:00
Adrian Johnson
f0ba2165a6 Add color palette option 2022-06-17 20:42:43 +09:30
Adrian Johnson
7c037e5254 dwrite: Fix incorrect rendering of some SVG fonts
SVG fonts are returning DWRITE_GLYPH_IMAGE_FORMATS_NONE as well
as DWRITE_GLYPH_IMAGE_FORMATS_SVG in GetCurrentRun() resulting in the
outline glyph and color glyph both rendered to the same glyph image.
2022-05-08 20:28:41 +09:30
Adrian Johnson
4815949d2f Fix the scaled_glyph_init color glyph logic
and split _cairo_user_scaled_glyph_init() into multiple functions.

Update user-font test to test changing foreground text color.
2022-04-25 17:08:07 +09:30
Adrian Johnson
e15a1e9a06 Fix mingw warning
it doesn't like '%lld' in snprintf
2022-04-19 19:58:44 +09:30
Adrian Johnson
90e6f2a9f7 DWrite: Replace manual or missing ref counting with RefPtr 2022-04-19 19:58:44 +09:30
Adrian Johnson
3998a79cc2 DWrite: check 'head' table as well as 'name' when comparing fonts
There may be different versions of fonts with the same name. As an
additional check, compare the 'head' table wich contains the checksum
for the font.

Also, load the DWrite tables directly to avoid the memcpy in
load_truetype_table.
2022-04-19 19:58:44 +09:30
Adrian Johnson
2b355954a8 DWrite: ensure all private functions are static 2022-04-19 19:58:44 +09:30
Adrian Johnson
655a8a40a7 Dwrite glyph_path fails when the font matrix is not a positive uniform scale 2022-04-19 19:58:44 +09:30