summaryrefslogtreecommitdiff
path: root/pango/pango-layout.c
Commit message (Collapse)AuthorAgeFilesLines
* Let get_items_log_attrs take the start-of-text offset into accountStephan Bergmann2020-09-101-2/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ...when interpreting item->offset values. I ran into this when executing tests of recent LibreOffice master with ASan on Fedora 32 (with pango-1.44.7-2.fc32.x86_64), where one of the tests renders various dialogs with a Tamil localization and failed with > ==97247==ERROR: AddressSanitizer: SEGV on unknown address 0x60b000210006 (pc 0x7fd6c5b22b54 bp 0x61d0004b4150 sp 0x7fff107a0d18 T0) > ==97247==The signal is caused by a READ memory access. > #0 in g_utf8_get_char at ../glib/gutf8.c:319:37 (/lib64/libglib-2.0.so.0 +0x85b54) > #1 in break_indic at ../pango/break-indic.c:119:17 (/lib64/libpango-1.0.so.0 +0x1076d) > #2 in break_script at ../pango/break.c:1896:7 (/lib64/libpango-1.0.so.0 +0x1076d) > #3 in tailor_break at ../pango/break.c:1606:9 (/lib64/libpango-1.0.so.0 +0x147db) > #4 in pango_tailor_break at ../pango/break.c:1774:7 (/lib64/libpango-1.0.so.0 +0x147db) > #5 in get_items_log_attrs at ../pango/pango-layout.c:4032:7 (/lib64/libpango-1.0.so.0 +0x2729c) > #6 in pango_layout_check_lines at ../pango/pango-layout.c:4289:7 (/lib64/libpango-1.0.so.0 +0x2729c) > #7 in pango_layout_get_extents_internal at ../pango/pango-layout.c:2623:3 (/lib64/libpango-1.0.so.0 +0x29068) > #8 in gtk_label_get_measuring_layout at /usr/src/debug/gtk3-3.24.22-1.fc32.x86_64/gtk/gtklabel.c:3376:3 (/lib64/libgtk-3.so.0 +0x2454d0) [...] From some debugging, it smells like `pango_layout_check_lines` calls `pango_itemize_with_base_dir` to compute `state.items` that are relative to the beginning of `layout->text`, but then passes `state.items` together with the offset'ed `start` into `get_items_log_attrs`, so that the latter misinterpreted the items' locations relative to the offset'ed start. Just adding g_assert (item->offset <= length); g_assert (item->length <= length - item->offset); to the original `get_items_log_attrs` would make various tests in the `meson test` suite fail, but which pass again with the complete fix, matching the above speculation.
* Handle analysis.font being NULLMatthias Clasen2020-08-181-0/+3
| | | | | | | | I don't think this is a legitimate concern, but it is faster to add a check than to argue about the use of pango on fontless systems. Fixes: #495
* layout: Avoid a crash with short stringsMatthias Clasen2020-07-301-0/+1
| | | | | | | | | | | You can call pango_layout_set_text() with a length that is longer than the string (and there's code in the wild that does that). We try to handle it by only looking at the initial segment of the text, but we are forgetting to set layout->length to the length of that segment, leading us to access beyond the string end later. This fixes #490
* Fix a crash in gtk2Matthias Clasen2020-06-101-5/+0
| | | | | | | Apparently, gtk2 assumes that calling pango_layout_set_attributes guarantees that the attribute list gains a ref. Fixes: #479
* layout: Ignore setting the attributes to the same listTimm Bäder2020-06-101-0/+4
|
* pango-layout: Help static analysis a bitTimm Bäder2020-06-101-0/+2
| | | | | Make sure we have a valid iter here, which is of course always the case in reality.
* layout: Fix a crashMatthias Clasen2020-06-091-12/+16
| | | | | pango_layout_get_effective_attributes can return NULL. But not all callers were handling that.
* Merge branch 'wip/baedert/for-master2' into 'master'Matthias Clasen2020-06-081-62/+113
|\ | | | | | | | | Wip/baedert/for master2 See merge request GNOME/pango!190
| * layout: Treat empty attr lists like NULL onesTimm Bäder2020-06-081-0/+6
| |
| * layout: Unconditionally unref attr listsTimm Bäder2020-06-081-5/+2
| |
| * pango-layout: Try to avoid allocating a new PangoAttrListTimm Bäder2020-06-081-5/+21
| |
| * layout: Avoid getting the text length if we know it alreadyTimm Bäder2020-06-081-7/+14
| |
| * Allocate internal PangoAttrLists on the stackTimm Bäder2020-06-081-11/+11
| |
| * layout: Add missing (nullable) annotationTimm Bäder2020-06-081-1/+2
| |
| * layotu: Avoid invalidating when setting attrs from NULL to NULLTimm Bäder2020-06-081-1/+5
| |
| * Allocate internal PangoAttrListIterators on the stackTimm Bäder2020-06-081-29/+31
| |
| * layout: Try to avoid some work when creating itersTimm Bäder2020-06-081-6/+19
| | | | | | | | | | Instead of getting the logical rect and then not using it, try not to compute it in the first place.
| * layout: Ignore setting the width if it won't have any effectTimm Bäder2020-06-081-0/+5
| | | | | | | | | | | | This is a pretty weak check (think e.g. a layout containing the text "a\na"), but it's very easy to do and still hits quite a few cases in real-world applications.
* | Use shape flags for tab widthJan Alexander Steffens (heftig)2020-02-111-1/+5
|/ | | | | | | | We need to apply the right shape flags to the tab width calculation, otherwise (when glyph positions get rounded, which is the default) our tab width will be slightly off from what 8 spaces normally produce. https://gitlab.gnome.org/GNOME/pango/issues/425
* Use shape flags for ellipsisMatthias Clasen2019-11-031-1/+6
| | | | | | | When shaping the ellipsis, use the same shape flags we use for the rest of the layout, otherwise we end up with subtle size differences between an ellipsized text and a plain …
* Don’t use underline position in overlinesKhaled Hosny2019-11-021-2/+2
| | | | | | This matches what web browsers do. Fixes https://gitlab.gnome.org/GNOME/pango/issues/432
* layout: Handle overline attributesMatthias Clasen2019-10-311-3/+24
|
* layout: Handle new underline valuesMatthias Clasen2019-10-311-0/+4
|
* Add pango_layout_get_directionMatthias Clasen2019-10-311-0/+26
| | | | | | | This lets callers access to resolved text direction of a layout. GTK needs this. Closes: https://gitlab.gnome.org/GNOME/pango/issues/14
* Fix ItemProperties handlingMatthias Clasen2019-10-281-29/+54
| | | | | | Deal with the fact that underlines and strikethroughs are not constant across items, since we do not break runs for these properties.
* Don't treat rise as a no-shape attributeMatthias Clasen2019-10-281-0/+1
| | | | | | | | It doesn't make sense to apply kerning between letters if they are not on the same baseline. This was not noticed so far, since it is very uncommon to have a rise without an accompanying font change, which will cause the run to be broken.
* Drop an unused ItemProperties useMatthias Clasen2019-10-281-3/+0
| | | | | We don't use ItemProperties in pango_layout_line_index_to_x anymore, so no need to compute them either.
* Go back to ignoring underlines for itemizationMatthias Clasen2019-10-281-5/+2
| | | | | | | | | This is what we used to do, and without it, we lose kerning beween underlined and non-underlined characters, which is most noticable with mnemonic underlines. Fixes: https://gitlab.gnome.org/GNOME/pango/issues/426
* Merge branch 'hyphen-crash' into 'master'Matthias Clasen2019-09-031-14/+1
|\ | | | | | | | | | | | | Drop some leftover code Closes #418 See merge request GNOME/pango!144
| * Drop some leftover codeMatthias Clasen2019-09-021-14/+1
| | | | | | | | | | | | | | | | In d6bc8daa6935b53c1, we added code to remove "hyphen runs". But we no longer create such runs, so this code is harmful and can cause crashes under certain circumstances. Closes: https://gitlab.gnome.org/GNOME/pango/issues/418
* | Disable hyphen for COMMON charactersPeng Wu2019-09-021-0/+1
|/ | | | The COMMON characters like symbol only line don't need hyphen.
* Disable hyphen for some languagesPeng Wu2019-08-281-0/+13
| | | | | Some languages like CJK languages, usually don't use the hyphen character.
* Fix a problem with allow-breaksMatthias Clasen2019-08-251-2/+1
| | | | | | | Fix an oversight in the calculation of log attributes. This was showing up as allow-breaks attributes being applied to the wrong ranges in later runs.
* Pass the right attributes when shaping ellipsesMatthias Clasen2019-08-061-1/+1
| | | | | | | | | | | | | | | Now that we are splitting attributes into those that are relevant for itemization and shaping, we need to make sure to pass the right ones along when ellipsizing, or we risk picking a wildly mismatching font for the ellipsis run, causing things to shift vertically. Test included. Closes: https://gitlab.gnome.org/GNOME/pango/issues/397 Thanks to Jorge Luis Martinez Gomez for his help in tracking this down.
* Add an insert-hyphens attributeMatthias Clasen2019-08-041-2/+35
| | | | | | | | | Add a text attribute that allows to suppress insertion of hyphens at intra-word line breaks. This is useful for non-paragraph-like contexts, where line breaks are needed, but hyphens are not expected.
* layout: Use the new glyph rounding optionMatthias Clasen2019-08-031-3/+9
| | | | | Take the glyph rounding option from PangoContext and translate it into a shape flag.
* Make line-spacing opt-inMatthias Clasen2019-08-021-2/+2
| | | | | | | | | Default the new line-spacing property to 0, so spacing continues to work. Applications can opt in to the new line-spacing behavior by setting a non-zero value. This should make spacing in the Gimp work again.
* Fix some issues with hyphensMatthias Clasen2019-07-271-18/+37
| | | | | | | | | We were inserting hyphens after spaces, and in some other places where they are not desirable. Fix this by looking at the characters on both sides of the break when deciding whether to insert a hyphen.
* layout: Don't zero the width of visible spaceMatthias Clasen2019-07-251-0/+4
| | | | | | | | | | | | | | Don't zero out a line separator at the end of line if we turned it into an unknown glyph to render it. And if we zero out whitespace at the end of the line, make sure we don't draw anything there by setting the glyph to EMPTY. Without this, we are getting the [LS] hex box rendered on top of the last character in a line, when the line separator ends up being visible.
* layout: Make tab visible tooMatthias Clasen2019-07-251-2/+24
| | | | | | When the 'show space' attribute is present, arrange for tab characters to be passed on to the rendering layer as non-empty.
* layout: Use a show attributeMatthias Clasen2019-07-251-0/+6
| | | | | Use an attribute to show line breaks in single-paragraph mode.
* layout: The show attribute affects shapingMatthias Clasen2019-07-251-0/+1
|
* layout: Flip the logic for attribute filteringMatthias Clasen2019-07-241-86/+88
| | | | | | | | | | | Instead of filtering out the attributes we don't want to influence itemization, explicitly filter only those attributes that we want to affect itemization. This makes us no longer break items for custom attributes, such as GtkTextAppearance attributes that are created by GtkTextLayout. Update expected output for layout testcases.
* layout: Fix misleading namingMatthias Clasen2019-07-241-17/+17
| | | | | | | What I called no_break_attrs are really no_itemize_attrs - some of them explicitly influence line breaking. So fix the misleading naming and call them what they are.
* Remove an unused functionMatthias Clasen2019-07-231-9/+0
|
* Fix a comment typoMatthias Clasen2019-07-221-1/+1
|
* layout: Pass offset to pango_tailor_breakMatthias Clasen2019-07-201-31/+10
| | | | This is necessary to interpret the attributes.
* Insert hyphens in more placesMatthias Clasen2019-07-201-2/+31
| | | | | | Look for whether the char before the break is not whitespace and doesn't look like a hyphen.
* Don't insert extra runs for hyphensMatthias Clasen2019-07-201-103/+30
| | | | | | | | | Instead, reshape the pre-break run with the soft hyphen replaced by an actual hyphen. This is unfortunately inefficient, we copy the entire text for this. The alternative (scatter-gather populating the harfbuzz buffer) is too hard to manage.
* Fix more compiler warningsMatthias Clasen2019-07-181-1/+1
| | | | These are clang warnings.