Bug 416393 - Emboldening of fonts is applied inconsistently
Summary: Emboldening of fonts is applied inconsistently
Status: RESOLVED DUPLICATE of bug 378523
Alias: None
Product: frameworks-ktexteditor
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: 5.66.0
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-01-17 20:43 UTC by Chris Spiegel
Modified: 2020-01-17 23:22 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Spiegel 2020-01-17 20:43:11 UTC
SUMMARY

If a non-normal font weight is selected (e.g. "Light"), and bold is explicitly set to 0 in katesyntaxhighlightingrc for a particular style item, it will be rendered as Normal instead of Light.

STEPS TO REPRODUCE

1. In Kate, choose a font and set its weight to Light
2. Choose a file which will be syntax highlighted and which has a comment in it (e.g. choose a C++ file with /* Some text */ in it)
3. Open ~/.config/katesyntaxhighlightingrc in an editor - modify the Comment line for both the "Default Item Styles - Schema [Your Style]" and the language you chose (e.g. "Highlighting C++ - Shema [Your Style]").  This line is a comma-separated list of values.  The first two entries are colors, and the third is a boolean specifying bold or not.  0 or empty means no, 1 means yes.  Set it explicitly to 0 (not empty)
4. Ensure all other bold style items in both sections are EMPTY, not 0
5. Open your chosen source file in kate

OBSERVED RESULT

The comment is bolder than the rest of the text.

EXPECTED RESULT

The comment is the same weight as the rest of the text.

ADDITIONAL INFORMATION

Here's what's happening: The following code is in katesyntaxmanager.cpp:

if (!tmp.isEmpty()) {
    i->setFontBold(tmp != QLatin1String("0"));
}

If the bold option is empty, then this block won't run.  If it's anything but 0, setFontBold(true) is called; and if it's 0, setFontBold(false) is called.

The problem is that setFontBold() looks like this:

void Attribute::setFontBold(bool bold)
{
    setFontWeight(bold ? QFont::Bold : QFont::Normal);
}

If it's not bold, it's assumed that it's normal.  But a light font was selected, so the resulting font is thicker than it ought to be (Normal being thicker than Light).  If the bold option is empty instead of 0, the method is never called, so the font remains Light.

The obvious fix is to only call setFontBold(true), and only when the entry is non-empty and non-zero.  But there are other callers to setFontBold(), so this wouldn't really address the underlying problem.  I think the real fix would be for setFontBold() to have knowledge of the current font selection: if it's called with false, set it to the user's selected weight; if it's true, set it to the "next bolder" weight.  But I don't know if that's possible.
Comment 1 Nate Graham 2020-01-17 23:22:37 UTC

*** This bug has been marked as a duplicate of bug 378523 ***