MantisBT - Open CASCADE
View Issue Details
0031678Open CASCADE[OCCT] OCCT:Visualizationpublic2020-07-21 13:352020-09-21 17:42
nds 
kgv 
normalfeature 
assignedopen 
 
[OCCT] 7.6.0* 
0031678: Visualization - add option enabling hinting for textured fonts
Setting color for text aspect gives different result in the viewer.

Calling the attached script on the current master and OCCT release 7.3.0 gives different result, shown on attached images.
pload ALL

vinit
vsetcolorbg 255 255 255
vlight -clear
vlight -add ambient
vtrihedron t1 -drawAxes XY -arrowColor 0 0 0 -color Whole 0 0 0 -textColor 0 0 0

vdrawtext text1 surprise -pos 100 100 0 -color 0 0 0 -height 20
vdrawtext text2 20.07.2020 -pos 100 -100 0 -color 0.1725 0.4745 0.70196 -height 20

vdrawtext text3 surprise -pos -200 100 0 -color 0 0 0 -height 20 -font "Segoe UI"
vdrawtext text4 20.07.2020 -pos -200 -100 0 -color 0.1725 0.4745 0.70196 -height 20 -font "Segoe UI"

vfit
vtop
vzoom 0.5
No tags attached.
child of 0029528closed apn Visualization, TKOpenGl - allow defining sRGB textures 
png text_on_occt730.png (7,873) 2020-07-21 13:35
https://tracker.dev.opencascade.org/
png text_on_occt_IR-2020-06-19.png (7,924) 2020-07-21 13:35
https://tracker.dev.opencascade.org/
png text_light_740.png (8,644) 2020-07-21 15:07
https://tracker.dev.opencascade.org/
png text_light_750dev.png (8,657) 2020-07-21 15:07
https://tracker.dev.opencascade.org/
png text_light_750dev_hinted.png (6,622) 2020-07-21 17:50
https://tracker.dev.opencascade.org/
png 31678_wi_comparing.png (76,765) 2020-07-23 11:26
https://tracker.dev.opencascade.org/
png krita_arrow_sRGB.png (65,753) 2020-07-23 14:08
https://tracker.dev.opencascade.org/
png krita_arrow_scRGB.png (65,870) 2020-07-23 14:08
https://tracker.dev.opencascade.org/
png freetype-27-hinting-comparison.png (28,908) 2020-07-23 19:57
https://tracker.dev.opencascade.org/
png a8_windows_nohint.png (26,482) 2020-07-25 20:26
https://tracker.dev.opencascade.org/
png a8_windows_hinted.png (23,636) 2020-07-25 20:26
https://tracker.dev.opencascade.org/
png a8_linux_nohint.png (26,098) 2020-07-25 20:26
https://tracker.dev.opencascade.org/
png a8_linux_hinted.png (25,921) 2020-07-25 20:27
https://tracker.dev.opencascade.org/
Issue History
2020-07-21 13:35ndsNew Issue
2020-07-21 13:35ndsAssigned To => kgv
2020-07-21 13:35ndsFile Added: text_on_occt730.png
2020-07-21 13:35ndsFile Added: text_on_occt_IR-2020-06-19.png
2020-07-21 14:03kgvRelationship addedchild of 0029528
2020-07-21 14:14kgvNote Added: 0093225
2020-07-21 14:15kgvNote Edited: 0093225bug_revision_view_page.php?bugnote_id=93225#r23160
2020-07-21 14:15kgvNote Edited: 0093225bug_revision_view_page.php?bugnote_id=93225#r23161
2020-07-21 15:07kgvFile Added: text_light_740.png
2020-07-21 15:07kgvFile Added: text_light_750dev.png
2020-07-21 15:08kgvNote Added: 0093229
2020-07-21 15:08kgvAssigned Tokgv => nds
2020-07-21 15:08kgvStatusnew => feedback
2020-07-21 15:09kgvNote Edited: 0093229bug_revision_view_page.php?bugnote_id=93229#r23165
2020-07-21 17:50kgvFile Added: text_light_750dev_hinted.png
2020-07-21 17:55kgvNote Added: 0093235
2020-07-23 11:26ndsFile Added: 31678_wi_comparing.png
2020-07-23 11:35ndsNote Added: 0093258
2020-07-23 11:35ndsAssigned Tonds => kgv
2020-07-23 11:35ndsStatusfeedback => assigned
2020-07-23 14:08kgvFile Added: krita_arrow_sRGB.png
2020-07-23 14:08kgvFile Added: krita_arrow_scRGB.png
2020-07-23 19:56kgvSeveritymajor => feature
2020-07-23 19:56kgvSummaryVisualization - text color becomes lighter than in 7.3.0 => Visualization - add option enabling hinting for textured fonts
2020-07-23 19:57kgvFile Added: freetype-27-hinting-comparison.png
2020-07-23 23:12gitNote Added: 0093273
2020-07-23 23:39kgvNote Added: 0093274
2020-07-23 23:41kgvNote Edited: 0093274bug_revision_view_page.php?bugnote_id=93274#r23169
2020-07-24 01:18kgvNote Added: 0093275
2020-07-24 01:18kgvAssigned Tokgv => nds
2020-07-24 01:18kgvStatusassigned => resolved
2020-07-24 01:48kgvAssigned Tonds => kgv
2020-07-24 01:48kgvStatusresolved => assigned
2020-07-24 02:28gitNote Added: 0093276
2020-07-25 20:22kgvFile Added: a8_windows_nohint.png
2020-07-25 20:22kgvFile Added: a8_windows_hinted.png
2020-07-25 20:22kgvFile Added: a8_linux_nohint.png
2020-07-25 20:22kgvFile Added: a8_linux_hinted.png
2020-07-25 20:26kgvFile Deleted: a8_linux_hinted.png
2020-07-25 20:26kgvFile Deleted: a8_linux_nohint.png
2020-07-25 20:26kgvFile Deleted: a8_windows_nohint.png
2020-07-25 20:26kgvFile Deleted: a8_windows_hinted.png
2020-07-25 20:26kgvFile Added: a8_windows_nohint.png
2020-07-25 20:26kgvFile Added: a8_windows_hinted.png
2020-07-25 20:26kgvFile Added: a8_linux_nohint.png
2020-07-25 20:27kgvFile Added: a8_linux_hinted.png
2020-07-25 20:30gitNote Added: 0093365
2020-07-27 08:33ndsNote Added: 0093366
2020-09-21 17:42kgvTarget Version7.5.0 => 7.6.0*

Notes
(0093225)
kgv   
2020-07-21 14:14   
(edited on: 2020-07-21 14:15)
This is not a bug, this is how graphics hardware performs color blending.

After 0029528, some text/background combinations become a little bit more readable and some less - no strict evidence that it become only worse has been identified on testing.

The workaround is adjusting colors / fonts / text styles for the cases, where readability looks unpleasant.

Disabling GL_FRAMEBUFFER_SRGB specifically for text elements can be considered option, but for now it does not look reasonable, as it just will make text blending worse/better for different backgrounds combinations. Better alternatives for rendering text to be investigated (no ideas so far).

(0093229)
kgv   
2020-07-21 15:08   
(edited on: 2020-07-21 15:09)
Test case in bug description is incorrect - it uses different text colors for OCCT 7.4.0 and for current master.

See attached screenshots for corrected test case:
pload MODELING VISUALIZATION
vinit View
vsetcolorbg 255 255 255
vlight -clear
vlight -add ambient
vtrihedron t1 -drawAxes XY -arrowColor 0 0 0 -color Whole 0 0 0 -textColor 0 0 0

vdrawtext text1 surprise -pos 100 100 0 -color BLACK  -height 20
vdrawtext text2 20.07.2020 -pos 100 -100 0 -color CORNFLOWERBLUE -height 20

vdrawtext text3 surprise -pos -200 100 0 -color BLACK -height 20 -font "Segoe UI"
vdrawtext text4 20.07.2020 -pos -200 -100 0 -color CORNFLOWERBLUE -height 20 -font "Segoe UI"


vfit
vtop
vzoom 0.5


(0093235)
kgv   
2020-07-21 17:55   
One more option is conditionally enabling hinting for such thin fonts.

Currently, hinting is disabled by FT_LOAD_NO_HINTING flag in Font_FTFont constructor, which according to documentation produces blurrier result.
This will not produce exactly the same result, but as it makes thin fonts less blurry, the blending with background has smaller effect.
(0093258)
nds   
2020-07-23 11:35   
Dear Kirill

commented flag FT_LOAD_NO_HINTING in Font_FTFont constructor gives better result (see 31678_wi_comparing.png).

It would be great if we may set it using some new additional method in OCCT for such parameter.

Thank you in advance, Natalia
(0093273)
git   
2020-07-23 23:12   
Branch CR31678 has been created by kgv.

SHA-1: cb8a329e48d8ec80a141edbee70ac8fa9cb9196b


Detailed log of new commits:

Author: kgv
Date: Thu Jul 23 22:39:27 2020 +0300

    0031678: Visualization - add option enabling hinting for textured fonts
    
    Added new rendering parameter Graphic3d_RenderingParams::ToEnableFontHinting
    allowing to enable/disable hinting (default is no hinting preserving old behavior).
    
    SelectMgr_ViewerSelector3d::ClearSensitive() - fixed crash on removing presentations.
    
    Command vrenderparams has been extended with arguments -fontHinting.
    In addition, added new parameters -sync and -reset for synchronizing parameters across Views;
    parameters -raster and -rayTrace now accept optional on|off values.
(0093274)
kgv   
2020-07-23 23:39   
(edited on: 2020-07-23 23:41)
Here is an elaboration about font rendering from FreeType developers:
https://www.freetype.org/freetype2/docs/text-rendering-general.html [^]

> The correct way of rendering a glyph image on a surface
> is to alpha blend it onto the surface in linear space
> and then apply gamma correction to translate the linear coverage map
> to something that is correct for our screens

So that current OCCT behavior more or less follows this guidance.

Hinting algorithms are expected to improve text readability in general on low-resolution screens (hopefully they will die some time).
However, there are a plenty of tricks around hinting (starting from patents, which have been expired circa '2011 according to FreeType).
Consider enabling this feature only on non-HiDPI screens at application level.

Note that OCCT does not support LCD-antialiasing of fonts (also useful only for low-resolution screens).

(0093275)
kgv   
2020-07-24 01:18   
Patch is ready for review in OCCT branch CR31678.

http://jenkins-test-12.nnov.opencascade.com:8080/view/CR31678-master-KGV [^]
(0093276)
git   
2020-07-24 02:28   
Branch CR31678 has been updated by kgv.

SHA-1: b0435d5aca1bacd41d22eea0c8d109053becc858


Detailed log of new commits:

Author: kgv
Date: Fri Jul 24 02:30:05 2020 +0300

    # update Font_FTFont::AdvanceX()

(0093365)
git   
2020-07-25 20:30   
Branch CR31678 has been updated forcibly by kgv.

SHA-1: 12c2257ae5e701c66148e601dbd7325f600d33be
(0093366)
nds   
2020-07-27 08:33   
Dear Kirill,

it would be also useful, if you provide your images with additional information:
- Font type,
- Font size,
- Free Type version.

Is it possible to have the same images on light(preferable white) background?

Thank you for investigations,
Natalia