summaryrefslogtreecommitdiff
path: root/src/cairo-scaled-font.c
Commit message (Collapse)AuthorAgeFilesLines
* doc: Fix the gtk-doc syntax of internal symbolsKhaled Hosny2023-02-021-0/+4
| | | | To stop gtk-doc from listing them as undocumented.
* Foreground color fixes for ft, svg, colrv1Adrian Johnson2023-01-271-12/+14
|
* Add new cairo_user_scaled_font_get_foreground_source() functionAdrian Johnson2023-01-261-14/+48
| | | | | | | | | | | | 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.
* [scaled-font] Clean up font-options before copyBehdad Esfahbod2023-01-191-0/+1
|
* Don't leave a font face in an error state after a scaled font creation failureFujii Hironori2023-01-101-2/+0
| | | | | | | | Scaled font creation may fail if the font size is very large on win32. But, don't leave the font face in an error state in such case. Fixes cairo/cairo#607
* Merge branch 'scaled-font-make-mutex-recursive' into 'master'Uli Schlachter2022-09-131-1/+1
|\ | | | | | | | | Make cairo_scaled_font_t::mutex recursive See merge request cairo/cairo!356
| * Make cairo_scaled_font_t mutex recursiveLuca Bacci2022-09-051-1/+1
| | | | | | | | | | Since it can now happen to acquire it recursively, see https://gitlab.freedesktop.org/cairo/cairo/-/issues/587
* | Check for scaled_font::cache_frozen in glyph_page_can_remove()Luca Bacci2022-09-051-1/+10
|/ | | | | | With modifications kindly suggested by Uli Schlachter Fixes https://gitlab.freedesktop.org/cairo/cairo/-/issues/587
* Remove unused codeAdrian Johnson2022-05-281-195/+0
|
* Fix deadlock in cairo-scaled-font.cAdrian Johnson2022-05-281-2/+35
| | | | | | | | | | | | | | | | A user font glyph containing a font can cause deadlock in _cairo_scaled_glyph_fini due to the destroy recording surface while holding _cairo_scaled_glyph_page_cache_mutex. When the font in the recording surface is removed from the page cache it will attempt to also acquire the _cairo_scaled_glyph_page_cache_mutex resulting in deadlock. Instead of destroying the recording surface in _cairo_scaled_glyph_page_cache_mutex, move it to an array in the scaled font and destroy it after the _cairo_scaled_glyph_page_cache_mutex is released. Fixes the font in user font case in #440
* Fix deadlock in cairo-scaled-font.cAdrian Johnson2022-05-281-3/+6
| | | | | | | | | | | | | | | | When cairo_scaled_glyph_page_cache needs to remove entries, cairo-cache calls _cairo_hash_table_random_entry() with the predicate _cairo_scaled_glyph_page_can_remove(). This function checks that the glyph_page scaled_font is not locked by testing scaled_font->cache_frozen. The scaled font is locked in the cache-cache destroy entry callback: _cairo_scaled_glyph_page_pluck(). There is a race condition here between testing scaled_font->cache_frozen and locking the font. Fix this by adding a new CAIRO_MUTEX_TRY_LOCK mutex operation, and using it to test and lock the scaled font in _cairo_scaled_glyph_page_can_remove(). Fixes the multithreaded case in #440
* Fix the scaled_glyph_init color glyph logicAdrian Johnson2022-04-251-1/+2
| | | | | | and split _cairo_user_scaled_glyph_init() into multiple functions. Update user-font test to test changing foreground text color.
* Fix a use after free in cairo_scaled_font_createFeysh INC2022-04-221-1/+1
| | | | | | | | | | | When `font_face` is freed by `cairo_font_face_destroy()` at line 1,150, the following call `_cairo_font_face_set_error (font_face, status)` causes a use after free. We moved up the `_cairo_font_face_set_error (font_face, status)` before `cairo_font_face_destroy()` to avoid the use after free. Signed-off-by: Feysh INC <opensource@feysh.com>
* Fix scaled_glyph hash lookup on Win64Adrian Johnson2022-04-191-2/+3
| | | | This was failing due to sizeof(uintptr_t) != sizeof(long) on Win64
* Merge branch 'master' into color-font-foreground-colorAdrian Johnson2021-09-171-1/+1
|\
| * Fix some MinGW warningsAdrian Johnson2021-09-021-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The FT change is because my MinGW build is using a more recent version of FT. Remove the disabled _cairo_win32_scaled_font_text_to_glyphs() code to fix the defined but not used warning. _cairo_win32_scaled_font_text_to_glyphs() was diabled in d9408041aa with the comment: "Currently disable the win32-font text_to_glyphs(), until that one is updated. Or better yet, remove it and implement ucs4_to_index(). It's the toy font API afterall." _cairo_win32_scaled_font_ucs4_to_index() was added in d1c619bc7d.
* | Support color fonts that use the foreground colorAdrian Johnson2021-08-281-3/+38
|/ | | | | | | | | | | | | COLR fonts can have a layer with the same color as the current text color. This change passes the current color (if solid) through to the font backend where it can be used to render color fonts. scaled_glyph_lookup checks if the foreground color has changed (for glyph that require it) and requests a new color surface if required. This also fixes a bug where scaled_glyph_lookup would always request a color surface for glyphs for glyphs in color fonts that do not have color.
* Change FNV hash to 64-bitAdrian Johnson2021-07-251-8/+8
| | | | | Most builds are 64-bit where the uintptr_t type of the hash value and the font face pointer that is being hashed are 64-bit.
* Use uintptr_t for all casts between pointer and integerAdrian Johnson2021-07-251-5/+5
| | | | | | | | | | | | On 64-bit windows, long is 32-bit. When compiling there are a large number of warnings about mismatched sizes when casting long to/from a pointer. Use the (u)intptr_t type for any integer that will have a pointer stored in it. Use a (u)intptr_t cast when integers are stored in pointers to silence warnings. Fixes #263
* Issue #482Glash Gnome2021-05-131-1/+1
| | | Documentation stanza
* fix double free and failed assertions in cairo_scaled_font_destroyMichal Sudolsky2020-10-211-4/+4
|
* scaled-font: Fix glyph and cluster count checks (CID #983386)Bryce Harrington2018-06-151-2/+2
| | | | | | | | | | | | | | | num_glyphs and num_clusters are explicitly checked to be non-NULL at the beginning of this routine, and by this point in the code both have been deref'd multiple times, so checking them for NULL here again is superfluous. It looks like the intent here is to verify the glyphs and clusters arrays are non-NULL unless their counts are zero, so change the tests accordingly. Coverity ID: #983386 Signed-off-by: Bryce Harrington <bryce@bryceharrington.org>
* Use _cairo_malloc instead of mallocAdrian Johnson2018-05-071-4/+4
| | | | | | | | | | _cairo_malloc(0) always returns NULL, but has not been used consistently. This patch replaces many calls to malloc() with _cairo_malloc(). Fixes: fdo# 101547 CVE: CVE-2017-9814 Heap buffer overflow at cairo-truetype-subset.c:1299 Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
* scaled-font: Fix assert when destroying glyph pageCarlos Garcia Campos2017-10-221-0/+7
| | | | | | | | | | | | | | | This happens when _cairo_ft_scaled_glyph_init() returns CAIRO_INT_STATUS_UNSUPPORTED when called from _cairo_scaled_glyph_lookup(). In those cases _cairo_scaled_font_free_last_glyph() is called to release the glyph that has just been allocated. If there aren't more glyphs, _cairo_scaled_glyph_page_destroy() is called. The problem is that _cairo_scaled_glyph_lookup() should always be called with the cache frozen, and _cairo_scaled_glyph_page_destroy() without the cache frozen. We can simply thaw/freeze the font before calling _cairo_scaled_glyph_page_destroy(). https://bugs.freedesktop.org/show_bug.cgi?id=103335
* Factor out the ISFINITE() macroBryce Harrington2017-10-111-6/+0
|
* Expose 'has color glyphs' as a scaled font propertyMatthias Clasen2017-07-291-0/+9
| | | | | | | This information will be used in subsequent commits to quickly decide that we won't try to handle glpyhs as masks. Implementing the new has_color_glyphs vfunc is optional - only backends that support color glyphs need to implement it.
* Add support for color glyphs to cairo_scaled_glyph_tMatthias Clasen2017-07-291-0/+21
| | | | | | | | | With this, glyphs can have either a surface that is expected to be used as mask, or a color_surface that should be used as source, or both. This will be used to support colored emoji glyphs that are stored as PNG images in OpenType fonts.
* Fix grammar in cairo_*_reference() function documentation.Bryce Harrington2016-10-101-2/+2
| | | | | | | "can be get" is incorrect grammar; "can be gotten" would be better, but active voice is best. Signed-off-by: Bryce Harrington <bryce@bryceharrington.org>
* scaled-font: Fix deadlock when recursing in _cairo_scaled_font_reset_cache()Hans Petter Jansson2016-08-021-6/+18
| | | | | | | | | | | The destruction of a scaled font could indirectly trigger the destruction of a second scaled font, causing the global cache to be locked twice in the same thread. This is solved by unlinking the font's glyph pages while holding the global lock, then releasing the lock before destruction takes place. Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=93891
* scaled-font: don't store pointer in hash valueAdrian Johnson2016-03-101-3/+4
|
* scaled-font: Prevent a recursive mutex lock for removing a failed glyphChris Wilson2013-06-181-0/+4
| | | | | | | | | | If we fail to create a glyph, and it is the only one in the glyph page, we then pluck that page out of the global glyph cache. The cache destroy callback tries to take the scaled_font lock again, causing a lockup. Rework the error path to avoid taking that lock in this case - still a potential lock ordering issue remains. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
* scaled-font: Fix use after free when clearing the glyph cacheChris Wilson2013-01-091-2/+3
| | | | Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
* scaled-font: Make reset-font-cache threadsafeChris Wilson2013-01-091-35/+31
| | | | | | | Stop trying to workaround the destroy-callback requiring the font mutex as we already hold the mutex whilst cleaning up the font caches. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
* scaled-font: Remove a non-threadsafe double-freeze assertChris Wilson2013-01-081-1/+0
| | | | | | | Sadly we cannot check ahead of acquiring the lock whether we hold the lock. Just have to rely on lockdep. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
* scaled-font: Hold the scaled font mutex whilst reaping from the global cacheChris Wilson2013-01-081-2/+7
| | | | | | | | | | | | | If we need to reap the global cache, this will call back into the scaled font to free the glyph page. We therefore need to be careful not to run concurrently with a user adding to the glyph page, ergo we need locking. To complicate matters we need to be wary of a lock-inversion as we hold the scaled_font lock whilst thawing the global cache. We prevent the deadlock by careful ordering of the thaw-unlock and by inspecting the current frozen state of the scaled-font before releasing the glyph page. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
* scaled-font: Assert if attempting to finish a frozen fontChris Wilson2013-01-081-0/+12
| | | | Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
* scaled-font: Free the cached glyphs from the font before taking the global lockChris Wilson2013-01-081-1/+20
| | | | | | | | | | | In the case of a recording surface we may recurse into the global glyph cache so we need to be careful and stage the ordering of how we free the glyphs. So first we finish any information and surfaces from the scaled font glyph cache (and so triggering recursion into other scaled fonts) and then take the global cache and remove our pages. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=54950 Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
* scaled-font: Always hold the mutex even for single glyph probesChris Wilson2013-01-081-20/+21
| | | | | | | | | | The freeze/thaw routines have a side-effect of managing the global glyph cache in addition to taking the mutex on the font. If we don't call them, we may end up indefinitely keeping the global glyph cache frozen (effectively leaking glyphs to the maximum of all open fonts) and triggering asserts. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
* scaled-font: Mention ownership of returned object from get_font_face()Chris Wilson2013-01-031-1/+2
| | | | | | As suggested by Simon Sapin. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
* xlib: Implement SHM fallbacks and fast upload pathsChris Wilson2012-08-171-1/+1
| | | | Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
* Use the new pixman_glyph_cache_t API that will be in pixman 0.28.0Søren Sandmann Pedersen2012-06-091-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This new pixman API allows glyphs to be cached and composited in one go, which reduces overhead compared to individual calls to pixman_image_composite_region32(). Notes: - There is an explicit call to _cairo_image_scaled_glyph_fini(). This could instead be done with a private, but I chose not to do that since we don't need to store any actual data; we only need notification when the glyph dies. - The slowdown in poppler-reseau is real and stable across runs. I'm not too concerned about it because this benchmark is only one run and so it is dominated by glyph cache setup costs and FreeType rasterizing. Performance results, image backend: Speedups firefox-talos-gfx 5571.55 -> 4265.57: 1.31x speedup gnome-terminal-vim 1875.82 -> 1715.14: 1.09x speedup evolution 1128.24 -> 1047.68: 1.08x speedup xfce4-terminal-a1 1364.38 -> 1277.48: 1.07x speedup Slowdowns poppler-reseau 374.42 -> 394.29: 1.05x slowdown Performance results, image16 backend: Speedups firefox-talos-gfx 5387.25 -> 4065.39: 1.33x speedup gnome-terminal-vim 2116.66 -> 1962.79: 1.08x speedup evolution 987.50 -> 924.27: 1.07x speedup xfce4-terminal-a1 1856.85 -> 1748.25: 1.06x speedup gvim 1484.07 -> 1398.75: 1.06x speedup Slowdowns poppler-reseau 371.37 -> 393.99: 1.06x slowdown Also bump pixman requirement to 0.27.1.
* scaled-font: Take lock around disposing of an empty page upon alloc failureChris Wilson2012-06-071-0/+2
| | | | | | | Spotted by code inspection whilst looking at #50705 References: https://bugs.freedesktop.org/show_bug.cgi?id=50705 Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
* composite-rectangles,scaled-font: Use accurate extents if the font is brokenChris Wilson2012-06-041-1/+10
| | | | | | | | If the font metrics appear broken, i.e. key values are being reported as zero, skip approximating the bbox of the glyph string. References: https://bugs.freedesktop.org/show_bug.cgi?id=50688 Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
* Revert "Use pixman glyphs"Søren Sandmann Pedersen2012-04-301-2/+0
| | | | | | This was pushed accidentally - apologies. This reverts commit 752c3b69e008b7d219da8cc5c657cf995732d3b8.
* Use pixman glyphsSøren Sandmann Pedersen2012-04-301-0/+2
|
* Split cairo-list into struct+inlinesChris Wilson2012-04-191-0/+1
| | | | | References: https://bugs.freedesktop.org/show_bug.cgi?id=48577 Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
* doc: Add "since" tag to documentationAndrea Canciani2012-03-291-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The following Python script was used to compute "Since: 1.X" tags, based on the first version where a symbol became officially supported. This script requires a concatenation of the the cairo public headers for the officially supported beckends to be available as "../../includes/1.X.0.h". from sys import argv import re syms = {} def stripcomments(text): def replacer(match): s = match.group(0) if s.startswith('/'): return "" else: return s pattern = re.compile( r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"', re.DOTALL | re.MULTILINE ) return re.sub(pattern, replacer, text) for minor in range(12,-2,-2): version = "1.%d" % minor names = re.split('([A-Za-z0-9_]+)', stripcomments(open("../../includes/%s.0.h" % version).read())) for s in names: syms[s] = version for filename in argv[1:]: is_public = False lines = open(filename, "r").read().split("\n") newlines = [] for i in range(len(lines)): if lines[i] == "/**": last_sym = lines[i+1][2:].strip().replace(":", "") is_public = last_sym.lower().startswith("cairo") elif is_public and lines[i] == " **/": if last_sym in syms: v = syms[last_sym] if re.search("Since", newlines[-1]): newlines = newlines[:-1] if newlines[-1].strip() != "*": newlines.append(" *") newlines.append(" * Since: %s" % v) else: print "%s (%d): Cannot determine the version in which '%s' was introduced" % (filename, i, last_sym) newlines.append(lines[i]) out = open(filename, "w") out.write("\n".join(newlines)) out.close()
* doc: Make documentation comments symmetricAndrea Canciani2012-03-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Documentation comments should always start with "/**" and end with "**/". This is not required by gtk-doc, but it makes the documentations formatting more consistent and simplifies the checking of documentation comments. The following Python script tries to enforce this. from sys import argv from sre import search for filename in argv[1:]: in_doc = False lines = open(filename, "r").read().split("\n") for i in range(len(lines)): ls = lines[i].strip() if ls == "/**": in_doc = True elif in_doc and ls == "*/": lines[i] = " **/" if ls.endswith("*/"): in_doc = False out = open(filename, "w") out.write("\n".join(lines)) out.close() This fixes most 'documentation comment not closed with **/' warnings by check-doc-syntax.awk.
* scaled-font: Ignore empty glyphs when checking for potential overlapHenry (Yu) Song2012-03-131-0/+3
| | | | | A zero-sized box contains no pixels and so cannot overlap, but it does still need to contribute to the extents.
* scaled-font: Assign a temporary hash value for the placeholderChris Wilson2012-02-281-0/+8
| | | | | | Fixes [large-]twin-antialias-mixed. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>