summaryrefslogtreecommitdiffstats
path: root/src/gui/text
Commit message (Collapse)AuthorAgeFilesLines
* QTextDocument: Add support for responsive imagesCarl Schwan3 days7-7/+87
| | | | | | | | | | | | | | | | Add support for the max-width css attribute in image. This allows images to be responsive: it adapts their size to the size of the QTextDocument so that they never grow bigger than the QTextDocument pageSize. This is implemented for the image handler used in QTextEdit and other QtWidget text related classes. [ChangeLog][QtGui][CSS] The max-width style can now be applied to <img/> to set the maximum width in pixels or percentage. Task-number: QTBUG-12283 Change-Id: Ic94e16279a1240ab4a509823de59dc0bfc920bb9 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* doc: Update note about variable axes on WindowsEskil Abrahamsen Blomfeldt3 days1-3/+1
| | | | | | | | Since Qt 6.8, the DirectWrite backend is the default, so we need to invert the warning. Change-Id: I0d32c06c3507664ecd5b1bc3ae3fcabeedee12b7 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
* Fix test compilation issues with QtLite configurationJari Helaakoski4 days1-2/+4
| | | | | | | | | | Now developer build tests compile, but some are not working. Functional fix will come later via separate tasks. Task-number: QTBUG-122999 Change-Id: I70487b46c1b32ba4279cb02a4978e4f55ac0d310 Reviewed-by: Alexey Edelev <alexey.edelev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Improve default style of QTextTableCarl Schwan10 days1-1/+2
| | | | | | | | | | Collapse the border and add some padding for the table cells. [ChangeLog][QtGui][Text] QTextTableFormat now defaults to collapsed tables with no spacing between cells. Change-Id: Ibebc92820447bd5fd9c0b905261dc4426b74358c Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* Introduce optional smarter font merging with ContextFontMergingEskil Abrahamsen Blomfeldt2024-04-2615-64/+150
| | | | | | | | | | | | | | | | | | | | | | This introduces an optional, slightly more expensive approach to font merging which takes the full string into account, instead of just going character by character. This addresses the issue that you may sometimes get multiple fonts to cover one string of text in a single language. With Chinese, this is especially an issue because many fonts will only support parts of the very large character set. The new algorithm detects if the string was incompletely covered by the font and tries the fallback fonts in order to find the best match. This is obviously more expensive, especially if no perfect match is found and we have to check all the fallbacks in the list, but it is opt-in and only enabled if the ContextFontMerging flag is set. Task-number: QTBUG-121131 Change-Id: I8c7874d0918640bd83418e3c4726c89f43a220a3 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
* QTextFormat: Use QMap::constFind() to avoid unnecessary detachesVladimir Belyavsky2024-04-211-8/+8
| | | | | | | | Use QMap::constFind() instead of non-const QMap::find() where applicable to avoid unnecessary detaches. Change-Id: I76113c00efabb592f565f3ba4c90aefead1ac6a0 Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
* Reverse fontconfig dominance logicAllan Sandfeld Jensen2024-04-191-40/+62
| | | | | | | | | | | | | | | | | | This changes four things: 1. The detection of Xft using platforms is now reversed assumed true, unless the desktop environment is traditionally Qt based. 2. When Xft using platforms are detected the Xft settings win over fontconfig settings. 3. On other platforms, Xft settings can still be used as a fallback if no fontconfig settings are found. 4. In case of no fontconfig match Xft settings are now applied, where before they would never be. Fixes: QTBUG-43745 Change-Id: I52372a6e2315441668eaf384046514fd6653e64a Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com> Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
* Draw list bullets/numbers with CSS text color, not palette colorShawn Rutledge2024-04-191-5/+3
| | | | | | | | | | | | | | | | | | | | | When CSS has been used to customize the text color, render the bullet with the same color. This is consistent with web browsers, and with Qt Quick rendering. In QTextDocumentLayoutPrivate::drawListItem(), the pen color is the text color, so use it instead of brush color. Add a baseline test for lancelot: the background and general text are customized, then some list items are customized further, and some of them have colored text spans. Repeat with different styles of numbered and bullet lists and checklists. Fixes: QTBUG-2188 Task-number: QTBUG-213 Task-number: QTBUG-57833 Pick-to: 6.5 6.7 Change-Id: I71e84d00172e4b37aef57c8badd2ec43c10113d9 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* Convert "(added in)" enum warnings to [since] syntaxAllan Sandfeld Jensen2024-04-181-1/+1
| | | | | | | | | | With the since syntax we can now mark since more standardized Pick-to: 6.7 Change-Id: I3c53010043a40e8887f1899cde2689ee80e530ae Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Jaishree Vyas <jaishree.vyas@qt.io>
* Add API to provide user-defined fallback fontsEskil Abrahamsen Blomfeldt2024-04-183-1/+129
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | When depending on Qt's font merging for providing glyphs for certain languages, there are currently some drawbacks. For one, you will typically get a system font which might not fit together with the main font of the application. In addition, you might get some glyphs from one font and other from another (typically for Chinese where the character sets are so large that fonts will often only implement parts). And finally, you may get the wrong glyphs for writing systems with regional differences, if your application is e.g. written in Japanese and then run on a Chinese system, you might get Chinese versions of characters which are shared between the languages. Without language-based font matching in Qt, there's no silver bullet for fixing this. This patch introduces API which makes it possible for users to provide the solution themselves, either by selecting application-provided fonts as fallbacks for certain scripts or by hardcoding system fonts for a specific language. [ChangeLog][Fonts] Added API to override default fallback font families for specific scripts. Task-number: QTBUG-121131 Change-Id: I23ee17b7dfe1c1e481c87cc67a05a0522841b598 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
* Support rendering CSS 'border' property for html tableSanthosh Kumar2024-04-183-12/+42
| | | | | | | | | | | | We supported CSS 'border-width', 'border-style' and 'border-color' for HTML tables since 8a9bec35fb0c60a0e5990c1a12ffe6f39fdbf2d. Now we also support the 'border' property, which is shorthand to set all four borders' width, style and color. Fixes: QTBUG-123167 Pick-to: 6.7 6.6 Change-Id: I5f29b94ab9facf412a9c230d554efb5c69368b6b Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* Add preliminary support for Qt for visionOSTor Arne Vestbø2024-04-181-1/+1
| | | | | | | | | | | | | | | | | | | | | | Qt already runs on Vision Pro as "Designed for iPad", using Qt for iOS. This change enables building Qt for visionOS directly, which opens the door to visionOS specific APIs and use-cases such as volumes and immersive spaces. The platform removes some APIs we depend on, notably UIScreen, so some code paths have been disabled or mocked to get something up and running. As our current window management approach on UIKit platforms depends on UIWindow and UIScreen there is currently no way to bring up QWindows. This will improve once we refactor our window management to use window scenes. To configure for visionOS, pass -platform macx-visionos-clang, and optionally add -sdk xrsimulator to build for the simulator. Change-Id: I4eda55fc3fd06e12d30a188928487cf68940ee07 Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
* QTextLayout: keep strong reference on font engine in a layout loopVladimir Belyavsky2024-04-161-17/+12
| | | | | | | | | | | | | | | | | | | This is speculative fix for the crashes in QTextLine::layout_helper() we're observing on users side. The possible reason is in that fontEngine and previousGlyphFontEngine, which are stored in LBH, became invalid during the layout cycle (destroyed by trimming font cache?). To prevent this we need to handle font engine's ref-counter gracefully, so just wrap them into QExplicitlySharedDataPointer. As a drive-by change, use in-class initialization for LBH members. Task-number: QTBUG-117500 Pick-to: 5.15 6.2 6.5 6.7 Change-Id: I6987a2b5618bb4ba8762f2ef01b4ce0dd60cb232 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
* Implement aliased text rendering with DirectWriteEskil Abrahamsen Blomfeldt2024-04-113-12/+44
| | | | | | | | | | | | | | | | | This creates aliased glyphs using the DirectWrite engine when requested. Note: There was previously a fallback to GDI to support aliased text, which ignored the hinting settings. This patch also removes that fallback. [ChangeLog][Windows] Support QFont::NoAntialias with the DirectWrite font engine. Pick-to: 6.5 6.6 6.7 Fixes: QTBUG-97645 Change-Id: I587f56ace468cfdd57debe7bc8492a96587a4e05 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* QTextMarkdownWriter: escape all backslashesShawn Rutledge2024-03-261-9/+4
| | | | | | | | | | | | | | | | | | A literal backslash needs to be doubled so that the parser doesn't treat it as escaping the following character when the markdown is read back. In ca4774131b9b8ee40b4d7f5c1ba296af4700207f we tried to limit it to backslashes that were not already escaped. In case someone really needs a longer series of backslashes, it's more correct to escape them all; but this comes with the risk that if they do not get un-escaped by the markdown parser in some scenario, repeated round-trip saving and loading could multiply them excessively. So we also add a lot of tests to try to verify that this is safe. Task-number: QTBUG-96051 Fixes: QTBUG-122083 Pick-to: 6.7 Change-Id: I64f610d24e99f67ebdc30d5ab5c6cf3985aec5ec Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
* Doc: explain how to check for the existence of a font familyMitch Curtis2024-03-191-1/+32
| | | | | | | | | | | | | bb6d68703b67e042e2a7254c2ca6a004a1441cc5 fixed warnings in the Universal style by using a faster alternative. It's possible that users will run into these warnings too, and they should be provided with information to make a more informed choice about which approach they can use. Fixes: QTBUG-123360 Pick-to: 6.5 6.6 6.7 Change-Id: I4170e9ade40c4b54dbc2bd73d124b2ade4d8c939 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
* Support foreground gradient in CSS parser and HTML generatorEskil Abrahamsen Blomfeldt2024-03-184-6/+66
| | | | | | | | | | | | | | | Qt supports some complex foreground brushes which we cannot express using normal CSS, so we introduce a Qt-specific property for this. We already had some support for background gradients in widget style sheets, but this expands support to foreground brushes of text when converting a QTextDocument from and to HTML. It also adds an optional "coordinatemode" attribute to the gradient functions so that this can be faithfully restored from HTML. Task-number: QTBUG-123357 Change-Id: I3d6dd828f68272995c8525bec5a7b421fdbed670 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
* Implement support for stroke color and width in CSS parserEskil Abrahamsen Blomfeldt2024-03-184-0/+34
| | | | | | | | | | | | | | | CSS does not have text outline properties, instead different browsers have custom properties for this. That currently means that you can have a QTextDocument where you applied a stroke to text and textEdit.setHtml(textEdit.toHtml()) will remove it. Since a primary goal of the HTML support in QTextDocument is that it can be used to save and faithfully restore its contents, we implement qt specific properties for stroke. Task-number: QTBUG-123357 Change-Id: Id9cf63abfabe2109ffb6fd74f9cb013304763ccb Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
* Fix default hinting with dpr scaling on WaylandEskil Abrahamsen Blomfeldt2024-03-183-7/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | When high-dpi scaling is enabled, we default to HintNone currently, since otherwise text layouts (and widget layouts and anything depending on text size) will have to be updated when the window is dragged onto a screen with a different dpr. The check for whether scaling is enabled was based on QHighDpiScaling::isActive(), which is technically incorrect since this does not return whether there is a scale on the painting, rather whether the coordinate system in Qt matches the one of the platform. Now that we support agreeing on fractional scale factors with the Wayland compositor, this issue has become visible, since QHighDpiScaling::isActive() will now return false for these compositors, even for fractional scales. For integer scales, the issue existed before as well, but the kerning issues are less noticeable in that case. Pick-to: 6.6 6.7 Fixes: QTBUG-122910 Change-Id: Ic82b07d57a06a351255619f9227dd60396903ade Reviewed-by: David Edmundson <davidedmundson@kde.org> Reviewed-by: Kai Uwe Broulik <kde@privat.broulik.de>
* Revert "Don't do font merging for PUA characters"Eskil Abrahamsen Blomfeldt2024-03-181-2/+1
| | | | | | | | | | | | | | This reverts commit fc33fea999365c36ed446eee0db0d59d94be306b. The change caused issues with system-wide PUA fallbacks on platforms where this is supported. It needs to be replaced by an approach which still falls back, but only for fonts which are explicitly categorized as PUA fallbacks. Pick-to: 6.5 6.6 6.7 Task-number: QTBUG-110502 Change-Id: I985a1f8076645593c50e81759872b4227d0fcd0d Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Fix QTextEngine regression with large-ish textsPaul Olav Tvete2024-03-152-7/+6
| | | | | | | | | | | | | | | Change 997fd3b88ede8078af286da6ecc197e83a8cbb46 fixed integer overflows with huge texts. This was done by using qsizetype for size calculations instead of int. However, that change introduced a serious regression due to an itermediate imultiplication result being "promoted" to unsigned, and therefore a negative value being converted to a large positive. The solution is to make sure all values in the expression are signed. Fixes: QTBUG-123339 Task-number: QTBUG-119611 Pick-to: 6.7 Change-Id: I3f9189f77b383c6103cf5b35981cdb607b065f6f Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
* QTextCursor: use QSV moreAnton Kudryavtsev2024-03-151-1/+1
| | | | | | | to avoid needless allocations Change-Id: I081119f3ee08a1cc6ec16745518c2ed75042dbf2 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* FreeType: reduce allocations in computeFaceIndexAnton Kudryavtsev2024-03-151-2/+2
| | | | | Change-Id: I6693f14b38be7d4fa09378674bcf5da1883608a4 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
* QTextMarkdownImporter: use string view moreAnton Kudryavtsev2024-03-131-9/+13
| | | | | | | | | to reduce allocations. While touching code, reorder condition and extract string literal to remove magic number Change-Id: I3972097dc9b976438e9ba0029f674cea2614f966 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QTextDocumentFragment: use range for moreAnton Kudryavtsev2024-03-131-4/+2
| | | | | | | to improve readability Change-Id: I42109e33fc076763c5b681d4837a81399c5aed5d Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* QTextMarkdownImporter::import(): don't crash if file has only yamlShawn Rutledge2024-03-051-1/+1
| | | | | | | | | | | If a markdown file has FrontMatter, we look for the end of the newlines after the `---` marker to begin parsing the actual markdown. But check bounds in case the file contains only front matter and not markdown. Fixes: QTBUG-122982 Change-Id: I09c4ae90c47ebd84877738aecc1d1cad0b0bfca2 Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru> Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
* Add categorized log message in QTextMarkdownWriter::writeFrontMatter()Shawn Rutledge2024-03-051-2/+4
| | | | | | | | | | There is logging in QTextMarkdownImporter::import(); in case something goes wrong, it's useful to compare the size during reading and writing. Amends bffddc6a993c4b6b64922e8d327bdf32e0d4975a Task-number: QTBUG-120722 Change-Id: I5f60305ca84d48f91bbb18e9c10ea4010005b356 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
* QTextMarkdownWriter: escape special characters (line or word prefix)Shawn Rutledge2024-03-041-3/+51
| | | | | | | | | | | | | | | | | | Try to avoid writing anything that the parser would misinterpret. Escape pre-existing backslashes, but not those that are already escaped. Optimize maybeEscapeFirstChar() slightly and apply it to every line of output (except in code blocks), not only to new lines created by word-wrapping. Since it would be hard to do this without using regular expressions, the markdown writer feature now depends on the regex feature. Fixes: QTBUG-96051 Fixes: QTBUG-122083 Pick-to: 6.7 Change-Id: I8d95366501fd31441829081c668f11a3a3a23fe2 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QTextEngine: Protect against integer overflow with huge textsPaul Olav Tvete2024-03-012-16/+17
| | | | | | | | | | | | | | | | QPlainTextEdit would crash when adding a string of 136 348 169 characters, due to the integer overflow checks being done with int variables. Perform intermediate calculations and size checks with qsizetype instead of int. This commit contains a slight modification of the fix contributed by Adam Clarke in the bug report. Note that the size check casts to size_t to cover the 32-bit case where qsizetype is qint32. Fixes: QTBUG-119611 Pick-to: 6.7 Change-Id: I1cf7e1bc4c35276862f37aa6d01f37075fa11635 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
* QTextHtmlImporter: don't forget to appendBlock after block tag closedShawn Rutledge2024-03-012-1/+5
| | | | | | | | | | | | | | | If we see a closing tag that really demands a new block after it, like </ul>, that needs to be done even if some ignorable whitespace and "inline" tags come after it. Don't get distracted by those. Also add a comment in QTextDocument::setHtml() to remind the reader that HTML parsing is a two-pass algorithm. Pick-to: 6.6 6.7 Fixes: QTBUG-81662 Change-Id: If723c9d3c211a684725055a06bcf87be4e38923a Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
* Fix -Wimplicit-fallthrough for clangTim Blechmann2024-03-011-0/+1
| | | | | | | | | | | | | | | | | | | Clang's `-Wimplicit-fallthrough` warnings are a little stricter than gcc's interpretation: switch (i) { case 0: foo(); case 4: break; } While gcc accepts the implicit fallthrough, if the following statement is a trivial `break`, clang will warn about it. Pick-to: 6.7 Change-Id: I38e0817f1bc034fbb552aeac21de1516edcbcbb0 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Fix color fonts with DirectWrite backendEskil Abrahamsen Blomfeldt2024-02-262-3/+4
| | | | | | | | | | | | The logic to detect color fonts in the GDI font database was never implemented in the DirectWrite database, causing emojis to look monochrome. The patch moves this into the font engine itself instead, along with the other initialization code. Pick-to: 6.7 Fixes: QTBUG-122168 Change-Id: I6f5dad579bd987149e613b8071821aaf70a89bc2 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Text widgets: document find() behavior with QRegularExpressionGiuseppe D'Angelo2024-02-261-0/+4
| | | | | | | | | | | | | | The various find() overloads that take a QRE *ignore* the case sensitivity option set on the QRE object itself. They instead apply the case sensitivity passed in the flags (see QTextDocument::find). I think it was an historic mishap, but it's too late to change now. Amend the documentation. Change-Id: I526650d89a98777c7bb839b27d2f2e536a43ca4f Pick-to: 6.7 6.6 6.5 6.2 5.15 Fixes: QTBUG-88721 Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch>
* Fix kerning errors when using DirectWrite backendEskil Abrahamsen Blomfeldt2024-02-151-3/+5
| | | | | | | | | | | | | | | | | | | | | | There were a couple of errors when calculating advances in the DirectWrite font engine: First of all, we would apply the CLEARTYPE_NATURAL glyph metrics when using GDI_CLASSIC rendering, causing text to look compressed in some places, because we always passed TRUE for the useGdiNatural parameter to GetGdiCompatibleGlyphMetrics(). In addition, we would pick the GDI-compatible metrics even when design metrics had explicitly been requested on the layout. This is the case for distance field rendered text, which always operates with design metrics and scalable layouts, so it was visible as kerning errors on some text there. Pick-to: 6.5 6.6 6.7 Fixes: QTBUG-122139 Fixes: QTBUG-122167 Change-Id: Ic28da6b3235d7af0452bdcb836e037594f8a20ba Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
* tst_QTextMarkdownWriter: test both ways of setting font characteristicsShawn Rutledge2024-02-141-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We have explicit QFont properties, and QTextFormat::setProperty(). Setting FontFixedPitch doesn't necessarily affect the view (QTextEdit or Qt Quick Text/TextEdit); and setting the font to the one we get from QFontDatabase::systemFont(QFontDatabase::FixedFont) is also unreliable, because the "monospace" fallback might actually be proportional. QTextMarkdownWriter checks for both to decide whether to use backticks; so markdown writing works if an editor UI makes the format monospace both ways to be safe. But in the opposite case that the main font is actually a monospace font, it's always been broken. The rest of the QTextCharFormat properties are generally working, to the extent that they are applicable to Markdown. But we lacked explicit test coverage: so far we were just reading Markdown or HTML and writing Markdown to test the writer. Also amend an old comment about writing underlines: writing was always possible, and since f5c7799f59ba53c634906b11e2135190093bf87b reading is supported too. So the underline support is symmetric (except that we don't heed the QTextDocument::MarkdownFeatures argument to the writer ctor: we probably should do that some day). Pick-to: 6.7 Task-number: QTBUG-54623 Task-number: QTBUG-75648 Task-number: QTBUG-75649 Task-number: QTBUG-79900 Task-number: QTBUG-99676 Task-number: QTBUG-103484 Change-Id: Iacb4ed0ea59030570702d4eadfdadfad872065c6 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
* QTextMarkdownWriter: Don't word-wrap headingsShawn Rutledge2024-02-131-1/+3
| | | | | | | | | If it wraps, the text on the next line is no longer part of the heading. Fixes: QTBUG-106526 Change-Id: I8015c948d875c6944422ef3439e3128af5b2a2e2 Pick-to: 6.5 6.6 6.7 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
* QTextMarkdownWriter: Avoid omitting or misplacing ending indicatorsShawn Rutledge2024-02-131-2/+21
| | | | | | | | | | | | | | | | | | | | | If we need to word-wrap a paragraph after a long formatted span, write any ending markers before the newline (amends 280d679c556ab8ead4748a627d7cd4c1950027fb ). Break before a fragment if the whole thing is past the column limit; in that case, write out any ending format markers before the newline. And now we have test coverage: prepend characters one-at-a-time to a line that already has a two-word formatted span at the end, and watch it successively break after the span, in the middle, and then before, while never putting a newline before the ending markers or failing to write them. Fixes: QTBUG-116927 Change-Id: I140e10d19a491cb599bf7ecf8514af866b5383f3 Pick-to: 6.5 6.6 6.7 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QTextMarkdownWriter: Handle lists in blockquotes correctlyShawn Rutledge2024-02-132-17/+53
| | | | | | | | | | | | | | But we do not yet handle a blockquote in a list item. Presumably that's less common anyway. We now also continue block-quote prefixes onto blank lines within a block quote, which looks more normal. Pick-to: 6.7 Task-number: QTBUG-104997 Change-Id: I2b5642cf3a0c81a94444a33f026a02ad53e7e6bb Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
* CoreText: Get user's preferred languages via NSLocale instead of NSUserDefaultsTor Arne Vestbø2024-02-131-1/+1
| | | | | | | | | | | | The latter API is considered a potential privacy risk, and needs explicit declaration of use for iOS in the privacy manifest, so avoid it if we can, to simplify things. Task-number: QTBUG-114319 Pick-to: 6.7 Change-Id: Ica6fef47720696bc9ab25cb25642d6650f618b70 Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com> Reviewed-by: Doris Verria <doris.verria@qt.io>
* Doc: Qt Gui: Fully qualify \variable documentationTopi Reinio2024-02-131-1/+1
| | | | | | | | | | | Upcoming changes to QDoc require API entities to be fully qualified; previously, QDoc maintained a list of 'open namespaces' that were part of matching the documented entity with its declaration, but that concept does not work for parallelized parsing where the order of processing can be arbitrary. Change-Id: I082d1b8c150543a1451767caf767ad5faf3473ba Reviewed-by: Luca Di Sera <luca.disera@qt.io>
* qfreetype: Fix caching of memory fontsMorten Sørvig2024-02-081-0/+9
| | | | | | | | | | | | | | | | | | | | | | Make QFreetypeFace::getFace() not return the same font face for all memory fonts. QtFreetypeData has a cache which maps QFontEngine::FaceId to QFreetypeFace instances. Each FaceId should then have a unique hash value, which is accomplished by by hashing the font file name and a stored uuid. However, we were not setting the uuid in all cases, which means that in-memory fonts (which do not have a file name) would hash identically. Fix this by setting the uuid to a value based on the address of the FontFile, which should be unique. Pick-to: 6.7 Change-Id: I45de37b512fb666c26490551c831c0db824b5f35 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* Fix memory leak in DirectWrite backendEskil Abrahamsen Blomfeldt2024-02-081-40/+24
| | | | | | | | | | | | | | This fixes a memory leak due to a missing call to release on the localized names in populateFamilyAliases(). The DirectWriteScope makes this automatic when it goes out of scope. We did release in the other places, but for hardening the code a bit, this also adjusts them to use the scope guard. Change-Id: I88402fad930e36cdd3a78244941fb53ca214520e Reviewed-by: Lars Knoll <lars@knoll.priv.no>
* Extract and re-write "front matter" in markdown documentsShawn Rutledge2024-02-027-3/+45
| | | | | | | | | | | | | | | | | | | | | | | | | | | | It's increasingly common for YAML to be used as metadata in front of markdown documents. md4c does not handle this, so we need to remove it ahead of time, lest md4c misinterpret it as heading text or so. The --- fences are expected to be consistent regardless of the format of what's between them, and the yaml (or whatever) parser does not need to see them. So we remove them while reading, and QTextMarkdownWriter writes them around the front matter if there is any. If your application needs to parse this "front matter", just call qtd->metaInformation(QTextDocument::FrontMatter).toUtf8() and feed that to some parser that you've linked in, such as yaml-cpp. Since YAML is used with GitHub Docs, we consider this feature to be part of the GitHub dialect: https://docs.github.com/en/contributing/writing-for-github-docs/using-yaml-frontmatter [ChangeLog][QtGui][Text] Markdown "front matter" (usually YAML) is now extracted during parsing (GitHub dialect) and can be retrieved from QTextDocument::metaInformation(FrontMatter). QTextMarkdownWriter also writes front matter (if any) to the output. Fixes: QTBUG-120722 Change-Id: I220ddcd2b94c99453853643516ca7a36bb2bcd6f Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
* Implement missing features in DirectWrite font backendEskil Abrahamsen Blomfeldt2024-02-026-103/+448
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | The DirectWrite font backend is an optional backend which is planned to take over as the default on Windows. In order to do this, though, a few gaps need to be filled in order for it to pass all autotests. The following things are covered by this: 1. Bitmap fonts are unsupported in DirectWrite. We enumerate these using GDI and fall back to the GDI font engine when loading them. As part of this, we introduce a new handle type for fonts on Windows which can represent both the DirectWrite and GDI engines. 2. "Legacy font names" where sub-family is embedded in the family name is now enumerated together with the typographic font name. 3. The DirectWrite font engine was not loading kerning pairs from the font, like the other engines (omission which was detected by the test) 4. Turning off antialiasing does not work with DirectWrite, so we fall back to GDI for this. 5. Loading supported writing systems from application fonts was not supported. Task-number: QTBUG-119420 Change-Id: Icf6c351afb0d7487b2f4634199088d701a324aae Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* freetype: Fix scaling layouts with bitmap fontsEskil Abrahamsen Blomfeldt2024-01-312-2/+8
| | | | | | | | | | | | | | The FreeType font engine would wrongly claim to support scaling transforms for bitmap fonts, despite ignoring the transform later. We do support this for color fonts through special casing, but for other bitmap fonts, we should return false and let the paint engine handle the scaling instead. Fixes: QTBUG-111796 Change-Id: I31732b909ef6e0c1afbf01ed4de1f67e994934c3 Reviewed-by: Lars Knoll <lars@knoll.priv.no> Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Support the named instances of Variable FontsAkira TAGOH2024-01-303-22/+83
| | | | | | | | | | | | | | | | | | In the fontconfig, the fonts will be populated with the variable font and the named instance from the variable font. In this patch, it will skip the variable font, and populate the named instances from the variable font. The FcFontMatch function ignores the FC_INDEX when match the font, changed the code to match the FC_INDEX by iterate the font list. [ChangeLog][Fonts] Added support for the named instances from the variable fonts. Pick-to: 6.7 Fixes: QTBUG-111994 Fixes: QTBUG-112136 Co-authored-by: Peng Wu <alexepico@gmail.com> Change-Id: Ic598d69a1e76109958fafa1226ea927656092319 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Fix infinite loop in QTextLayout with setNumColumns()Eskil Abrahamsen Blomfeldt2024-01-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | If the line width is negative, then we might exit the layout loop before consuming any text, and thus the loop will never finish. This is a side effect of a change for maximumWidth: 991c056438b311566bc4ea543af0f33dfd5dffbb. 49a63d375972079ae3000c8b7d512d58d4de32bb fixed this issue for QTextLayout::setFixedSize(), but I forgot to do the same in the overload of QTextLayout::setNumColumns() which includes an alignment width and therefore sets the line width in addition to the column count. Basically, we just make sure the line width is never negative so that the width > line.width condition also means the width > 0. Pick-to: 6.5 6.6 6.7 Fixes: QTBUG-115459 Change-Id: If904bfc64cd74e819a0864db55fa9555073d0781 Reviewed-by: Vladimir Belyavsky <belyavskyv@gmail.com> Reviewed-by: Lars Knoll <lars@knoll.priv.no>
* windows: Avoid infinite recursion with certain fontsEskil Abrahamsen Blomfeldt2024-01-251-10/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Amends 922d195020d54d7e599d135f6a5e0338100e08f1. Another infinite recursion was found in the case of populating font families for cases where the typographical name is different from the populated name. The specific font triggering this had two "preferred name" entries in its name data. This was one for Chinese (PRC) and another for Chinese (Taiwan). Our GDI backend does not do matching based on locale, but will prefer the English if available, otherwise it will just pick the first one. The font in question does not have the English preferred name. For this particular font, we would select the Chinese (Taiwan) name as preferred and since it had not been populated, we would populate this. However, on Chinese (PRC) locale, Windows would report this according to the Chinese (PRC) name. We would once again translate this to Chinese (Taiwan) and go into an infinite recursion populating it. The quick fix is to mark the preferred family as populated before entering the recursion, so that we do not re-populate it a second time later. Ideally, the font database would match the preferred name based on locale, but since we are moving away from the GDI font database and this is already handled better with the DirectWrite database, just fixing the recursion is sufficient here. [ChangeLog][Windows] Fixed an issue where an infinite recursion could occur if the system had a font with multiple preferred names in non-English languages. Pick-to: 5.15 6.2 6.5 6.6 6.7 Fixes: QTBUG-118238 Change-Id: I6ded369f1c908e51c0ba2ad9127538faf07e192e Reviewed-by: Lars Knoll <lars@knoll.priv.no> Reviewed-by: Liang Qi <liang.qi@qt.io>
* Fix clipped text when combining multiple writing systemsEskil Abrahamsen Blomfeldt2024-01-251-171/+193
| | | | | | | | | | | | | | | | | | | When a QTextLine consists of multiple different scripts and the fonts had negative bearing, the background for a script item could overdraw the previous item's text, causing it to look clipped. This was because the background and text was drawn in a single pass, and moving the background drawing into its own pre-pass fixes the issue. [ChangeLog][QtGui] Fixed an issue where drawing text from different writing systems in the same line and including a background could cause parts of the text to be clipped. Pick-to: 6.5 6.6 6.7 Fixes: QTBUG-121040 Change-Id: I3f79e6d33c09a2a92853bc8752dbe11a0bea2dd0 Reviewed-by: Lars Knoll <lars@knoll.priv.no>
* Fix out of bounds access during QTextDocument cloningJoni Poikelin2024-01-231-1/+1
| | | | | | | Fixes: QTBUG-120962 Pick-to: 6.5 6.6 6.7 Change-Id: Ib2a35acd5a0d673b39556a4aa930e37eb40b39b2 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>