MantisBT
Mantis Bug Tracker Workflow

View Issue Details Jump to Notes ] Related Changesets ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0031720Community[OCCT] OCCT:Visualizationpublic2020-08-19 20:142020-08-22 16:12
ReporterVico Liang 
Assigned Tobugmaster 
PrioritynormalSeverityminor 
StatusverifiedResolutionfixed 
PlatformOSOS Version
Product Version[OCCT] 7.4.0 
Target Version[OCCT] 7.5.0Fixed in Version 
Summary0031720: Visualization, Font_FontMgr - register one more CJK fallback font available on newer Android devices
DescriptionFont_BRepFont has been tested to create shape for Chinese text. The test environment is on Android device. Any font not supported for Chinese will display a rectangle as its placeholder.

The problem may occur in below method: HasSymbol(theUChar) returns true even if it doesn't support Chinese because it has a placeholder for it.

bool Font_FTFont::loadGlyph (const Standard_Utf32Char theUChar)
{
  if (myUChar == theUChar)
  {
    return myUChar != 0;
  }

  myGlyphImg.Clear();
  myUChar = 0;
  myActiveFTFace = myFTFace;
  if (theUChar == 0)
  {
    return false;
  }

  if (myToUseUnicodeSubsetFallback
  && !HasSymbol (theUChar))
  {
    // try using fallback
    const Font_UnicodeSubset aSubset = CharSubset (theUChar);
    if (findAndInitFallback (aSubset)
     && myFallbackFaces[aSubset]->HasSymbol (theUChar))
    {
      myActiveFTFace = myFallbackFaces[aSubset]->myFTFace;
    }
  }

  if (FT_Load_Char (myActiveFTFace, theUChar, FT_Int32(myLoadFlags)) != 0
   || myActiveFTFace->glyph == NULL)
  {
    return false;
  }

  myUChar = theUChar;
  return true;
}
TagsNo tags attached.
Test case numberNot required
Attached Files? file icon DroidSans.ttf (306,672 bytes) 2020-08-20 16:34
png file icon occ_jni_cjk_KO.png (104,452 bytes) 2020-08-21 11:47
png file icon occ_jni_cjk_OK.png (101,471 bytes) 2020-08-21 11:47

- Relationships
related to 0031728verifiedbugmaster Community Visualization, Font_FontMgr - provide function to register fallback fonts in application level 
has duplicate 0031719closedbugmaster Community no default Chinese Unicode support 
child of 0030782closedbugmaster Open CASCADE Visualization, Font_FTFont - use predefined fallback fonts for extended Unicode subsets 

-  Notes
(0093555)
Vico Liang (developer)
2020-08-19 20:30

Hope HasSymbol method can work more precisely and make the fallback works.
(0093556)
kgv (developer)
2020-08-19 20:36

I don't think that HasSymbol() is a problem - correct fonts should not provide a placeholder for it (such placeholder is normally returned in a different way).

Would be helpful to know exactly font used in this case to verify if problem is with it or somewhere else.
(0093557)
Vico Liang (developer)
2020-08-19 20:48

Android devide, font name: Roboto is a good case to reproduce the issue.
(0093565)
kgv (developer)
2020-08-20 16:37
edited on: 2020-08-20 16:39

With DroidSans.ttf (Roboto) from Android 7 device (attached to the bug):

pload MODELING VISUALIZATION
dtracelevel trace
vfont -verbose 1
#vfont -clear
vfont -add DroidSans.ttf
vinit View1
vtop
vpoint p00  0  0 0;vpoint p01  0 10 0;vpoint p11 10 10 0;vpoint p10 10  0 0
vfit
vzoom 0.8
vdrawtext t2 "简体中文 (Chinese)"    -pos  0  2 0 -halign left  -font Roboto


prints (on Windows):
Font_FontMgr, using font alias 'SimSun' instead of requested 'cjk'
Font_FTFont, using fallback font 'SimSun' for symbols unsupported by 'Roboto'


So that checking for a range looks as expected for this font as fallback is used. Do you have another result with Roboto font from your device?
Or maybe fallback found it actually not found or used a bad one?

(0093568)
Vico Liang (developer)
2020-08-20 17:20
edited on: 2020-08-20 17:20

whatever font are used, the unicode Chinese display as expected on Windows.
The problem occurs on mobile devices Android and iOS.

I'm not sure if it's suitable to attached the app link for you to see the issue.

https://play.google.com/store/apps/details?id=com.wuweido.cad [^]
https://apps.apple.com/app/id1470242832 [^]

(0093579)
git (administrator)
2020-08-21 11:49

Branch CR31720 has been created by kgv.

SHA-1: 46202841b3c27afe6782f1635d78579d51aa86d3


Detailed log of new commits:

Author: kgv
Date: Fri Aug 21 11:52:15 2020 +0300

    0031720: Visualization, Font_FontMgr - register one more CJK fallback font available on newer Android devices
(0093581)
kgv (developer)
2020-08-21 11:58

Vico,

Font_FontMgr registers fallback fonts in constructor via addFontAlias() method in constructor. This logic is fragile, as it is based on the knowledge of standard font families pre-installed on specific platforms (and OS vendors tend to change fonts from version to version).

Newer Android devices are shipped with "Noto Sans CJK JP" font family supporting CJK characters. I have added this font in CR31720 - see attached screenshots of JNI sample:

void OcctJni_Viewer::initContent()
...
+    myViewCube->SetBoxSideLabel (V3d_TypeOfOrientation_Zup_Top, u8"简体中文 go");
  
}
  myContext->Display (myViewCube, false);


iOS is a different story, as this closed platform does not permit file access to standard fonts, and the only way to draw text there is shipping some fonts with application itself and registering them within Font_FontMgr (of course, this option is available on other platforms as well to ensure all necessary fonts are available, but this raises additional legal issues for finding free/buying fonts and bloats application binary with extra files).
(0093582)
kgv (developer)
2020-08-21 12:02
edited on: 2020-08-21 14:13

I'm curious, if Android 11 involves some new restrictions to file access to system fonts (as Google tries to lock up a normal file system access), or it remains permitted there...

(0093583)
kgv (developer)
2020-08-21 14:14

Patch is ready for review in OCCT branch CR31720.

http://jenkins-test-12.nnov.opencascade.com:8080/view/CR31720-master-KGV/ [^]
(0093584)
Vico Liang (developer)
2020-08-21 14:49

Dear KGV,

Thanks for working on this and knowledge sharing.I checked that method addFontAlias() is private, it would be great if it's public, if so developers have chances to register fallback fonts.
(0093585)
osa (developer)
2020-08-21 14:50

The patch was reviewed
(0093596)
bugmaster (administrator)
2020-08-22 16:02

Combination -
OCCT branch : IR-2020-08-21
master SHA - 1d99a2baaa614856d8ef8b0a9975af5c3bdf92c6
a206de37fbfa0bf71bd534ae47192bbec23b8522
Products branch : IR-2020-08-21 SHA - 9541102e96ff9ee3aeec6e3e32f20f63b3b38556
was compiled on Linux, MacOS and Windows platforms and tested in optimize mode.

Number of compiler warnings:
No new/fixed warnings

Regressions/Differences/Improvements:
No regressions/differences

CPU differences:
Debian80-64:
OCCT
Total CPU difference: 17322.48000000014 / 17160.470000000118 [+0.94%]
Products
Total CPU difference: 11882.560000000085 / 11820.020000000079 [+0.53%]
Windows-64-VC14:
OCCT
Total CPU difference: 18716.078125 / 18725.125 [-0.05%]
Products
Total CPU difference: 13242.09375 / 13316.109375 [-0.56%]


Image differences :
No differences that require special attention

Memory differences :
No differences that require special attention
(0093597)
git (administrator)
2020-08-22 16:12

Branch CR31720 has been deleted by inv.

SHA-1: 46202841b3c27afe6782f1635d78579d51aa86d3

- Related Changesets
occt: master 1d99a2ba
Timestamp: 2020-08-21 08:52:15
Author: kgv
Committer: bugmaster
Details ] Diff ]
0031720: Visualization, Font_FontMgr - register one more CJK fallback font available on newer Android devices
mod - src/Font/Font_FontMgr.cxx Diff ] File ]

- Issue History
Date Modified Username Field Change
2020-08-19 20:14 Vico Liang New Issue
2020-08-19 20:14 Vico Liang Assigned To => kgv
2020-08-19 20:20 kgv Relationship added has duplicate 0031719
2020-08-19 20:30 Vico Liang Note Added: 0093555
2020-08-19 20:36 kgv Note Added: 0093556
2020-08-19 20:48 Vico Liang Note Added: 0093557
2020-08-20 16:34 kgv File Added: DroidSans.ttf
2020-08-20 16:37 kgv Note Added: 0093565
2020-08-20 16:38 kgv Note Edited: 0093565 View Revisions
2020-08-20 16:38 kgv Assigned To kgv => Vico Liang
2020-08-20 16:38 kgv Status new => feedback
2020-08-20 16:38 kgv Note Edited: 0093565 View Revisions
2020-08-20 16:39 kgv Note Edited: 0093565 View Revisions
2020-08-20 17:20 Vico Liang Note Added: 0093568
2020-08-20 17:20 Vico Liang Note Edited: 0093568 View Revisions
2020-08-20 18:01 Vico Liang Assigned To Vico Liang => kgv
2020-08-21 11:47 kgv File Added: occ_jni_cjk_KO.png
2020-08-21 11:47 kgv File Added: occ_jni_cjk_OK.png
2020-08-21 11:49 kgv Summary fallback fonts not applied for unicode Chinese since most font have a placeholder for unsupported character. => Visualization, Font_FontMgr - register one more CJK fallback font available on newer Android devices
2020-08-21 11:49 git Note Added: 0093579
2020-08-21 11:58 kgv Note Added: 0093581
2020-08-21 12:02 kgv Note Added: 0093582
2020-08-21 12:23 kgv Note Edited: 0093582 View Revisions
2020-08-21 14:13 kgv Note Edited: 0093582 View Revisions
2020-08-21 14:14 kgv Note Added: 0093583
2020-08-21 14:14 kgv Assigned To kgv => osa
2020-08-21 14:14 kgv Status feedback => resolved
2020-08-21 14:14 kgv Product Version => 7.4.0
2020-08-21 14:14 kgv Relationship added child of 0030782
2020-08-21 14:49 Vico Liang Note Added: 0093584
2020-08-21 14:50 osa Note Added: 0093585
2020-08-21 14:50 osa Assigned To osa => bugmaster
2020-08-21 14:50 osa Status resolved => reviewed
2020-08-21 15:22 Vico Liang Relationship added related to 0031728
2020-08-22 16:02 bugmaster Note Added: 0093596
2020-08-22 16:02 bugmaster Status reviewed => tested
2020-08-22 16:05 bugmaster Test case number => Not required
2020-08-22 16:06 bugmaster Changeset attached => occt master 1d99a2ba
2020-08-22 16:06 bugmaster Status tested => verified
2020-08-22 16:06 bugmaster Resolution open => fixed
2020-08-22 16:12 git Note Added: 0093597


Copyright © 2000 - 2020 MantisBT Team
Powered by Mantis Bugtracker