1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-03 17:56:21 +03:00

0031079: Visualization - embed minimal fallback font

Font_FTFont::FindAndCreate() now loads embedded fallback font within Font_StrictLevel_Any level.
Font_FontMgr::FindFont() - fixed misprint in message, and customized message for range fallback error.
Font_FontMgr - added one more fallback Korean font for Linux.

vfont command has been extended with options to clear Font Manager content.
This commit is contained in:
kgv 2019-10-18 11:40:55 +03:00 committed by apn
parent 215dd33149
commit 36e28f96f6
9 changed files with 1773 additions and 14 deletions

View File

@ -153,6 +153,9 @@ on this tool.
**RapidJSON** is an Open Source JSON parser and generator for C++.
RapidJSON is optionally used by OCCT for reading glTF files (https://rapidjson.org/).
**DejaVu** fonts are a font family based on the Vera Fonts under a permissive license (MIT-like, https://dejavu-fonts.github.io/License.html).
DejaVu Sans (basic Latin sub-set) is used by OCCT as fallback font when no system font is available.
Adobe Systems, Inc. provides **Adobe Reader**, which can be used to view files in Portable Document Format (PDF).
@section OCCT_OVW_SECTION_3 Documentation

View File

@ -18,3 +18,4 @@ Font_SystemFont.hxx
Font_TextFormatter.hxx
Font_TextFormatter.cxx
Font_UnicodeSubset.hxx
Font_DejavuSans_Latin_woff.pxx

File diff suppressed because it is too large Load Diff

View File

@ -21,6 +21,8 @@
#include <Message.hxx>
#include <Message_Messenger.hxx>
#include "Font_DejavuSans_Latin_woff.pxx"
#include <algorithm>
#include <ft2build.h>
@ -156,9 +158,9 @@ Handle(Font_FTFont) Font_FTFont::FindAndCreate (const TCollection_AsciiString& t
{
Handle(Font_FontMgr) aFontMgr = Font_FontMgr::GetInstance();
Font_FontAspect aFontAspect = theFontAspect;
Font_FTFontParams aParams = theParams;
if (Handle(Font_SystemFont) aRequestedFont = aFontMgr->FindFont (theFontName, theStrictLevel, aFontAspect))
{
Font_FTFontParams aParams = theParams;
if (aRequestedFont->IsSingleStrokeFont())
{
aParams.IsSingleStrokeFont = true;
@ -172,6 +174,31 @@ Handle(Font_FTFont) Font_FTFont::FindAndCreate (const TCollection_AsciiString& t
return aFont;
}
}
else if (theStrictLevel == Font_StrictLevel_Any)
{
switch (theFontAspect)
{
case Font_FontAspect_UNDEFINED:
case Font_FontAspect_Regular:
case Font_FontAspect_Bold:
aFontAspect = Font_FontAspect_Regular;
break;
case Font_FontAspect_Italic:
case Font_FontAspect_BoldItalic:
aFontAspect = Font_FontAspect_Italic;
aParams.ToSynthesizeItalic = true;
break;
}
Handle(NCollection_Buffer) aBuffer = new NCollection_Buffer (Handle(NCollection_BaseAllocator)(),
Font_DejavuSans_Latin_woff_size,
const_cast<Standard_Byte*>(Font_DejavuSans_Latin_woff));
Handle(Font_FTFont) aFont = new Font_FTFont();
if (aFont->Init (aBuffer, "Embed Fallback Font", aParams))
{
aFont->myFontAspect = aFontAspect;
return aFont;
}
}
return Handle(Font_FTFont)();
}
@ -197,6 +224,18 @@ bool Font_FTFont::FindAndInit (const TCollection_AsciiString& theFontName,
const TCollection_AsciiString& aPath = aRequestedFont->FontPathAny (myFontAspect, aParams.ToSynthesizeItalic);
return Init (aPath, aParams);
}
else if (theStrictLevel == Font_StrictLevel_Any)
{
if (theFontAspect == Font_FontAspect_Italic
|| theFontAspect == Font_FontAspect_BoldItalic)
{
aParams.ToSynthesizeItalic = true;
}
Handle(NCollection_Buffer) aBuffer = new NCollection_Buffer (Handle(NCollection_BaseAllocator)(),
Font_DejavuSans_Latin_woff_size,
const_cast<Standard_Byte*>(Font_DejavuSans_Latin_woff));
return Init (aBuffer, "Embed Fallback Font", aParams);
}
Release();
return false;
}

View File

@ -303,6 +303,7 @@ Font_FontMgr::Font_FontMgr()
aKorean->Append (Font_FontAlias ("nanummyeongjo")); // Linux
aKorean->Append (Font_FontAlias ("noto serif cjk jp")); // Linux
aKorean->Append (Font_FontAlias ("noto sans cjk jp")); // Linux
aKorean->Append (Font_FontAlias ("droid sans fallback")); // Linux
#if defined(_WIN32)
anArab->Append (Font_FontAlias ("times new roman"));
@ -390,6 +391,15 @@ Standard_Boolean Font_FontMgr::RegisterFont (const Handle(Font_SystemFont)& theF
return Standard_True;
}
// =======================================================================
// function : ClearFontDataBase()
// purpose :
// =======================================================================
void Font_FontMgr::ClearFontDataBase()
{
myFontMap.Clear();
}
// =======================================================================
// function : InitFontDataBase
// purpose :
@ -742,14 +752,27 @@ Handle(Font_SystemFont) Font_FontMgr::FindFallbackFont (Font_UnicodeSubset theSu
Font_FontAspect theFontAspect) const
{
Font_FontAspect aFontAspect = theFontAspect;
Handle(Font_SystemFont) aFont;
switch (theSubset)
{
case Font_UnicodeSubset_Western: return FindFont (Font_NOF_SANS_SERIF, Font_StrictLevel_Aliases, aFontAspect);
case Font_UnicodeSubset_Korean: return FindFont (Font_NOF_KOREAN, Font_StrictLevel_Aliases, aFontAspect);
case Font_UnicodeSubset_CJK: return FindFont (Font_NOF_CJK, Font_StrictLevel_Aliases, aFontAspect);
case Font_UnicodeSubset_Arabic: return FindFont (Font_NOF_ARABIC, Font_StrictLevel_Aliases, aFontAspect);
case Font_UnicodeSubset_Western: aFont = FindFont (Font_NOF_SANS_SERIF, Font_StrictLevel_Aliases, aFontAspect, false); break;
case Font_UnicodeSubset_Korean: aFont = FindFont (Font_NOF_KOREAN, Font_StrictLevel_Aliases, aFontAspect, false); break;
case Font_UnicodeSubset_CJK: aFont = FindFont (Font_NOF_CJK, Font_StrictLevel_Aliases, aFontAspect, false); break;
case Font_UnicodeSubset_Arabic: aFont = FindFont (Font_NOF_ARABIC, Font_StrictLevel_Aliases, aFontAspect, false); break;
}
return Handle(Font_SystemFont)();
if (aFont.IsNull())
{
const char* aRange = "";
switch (theSubset)
{
case Font_UnicodeSubset_Western: aRange = "Western"; break;
case Font_UnicodeSubset_Korean: aRange = "Korean"; break;
case Font_UnicodeSubset_CJK: aRange = "CJK"; break;
case Font_UnicodeSubset_Arabic: aRange = "Arabic"; break;
}
Message::DefaultMessenger()->Send (TCollection_AsciiString("Font_FontMgr, error: unable to find ") + aRange + " fallback font!", Message_Fail);
}
return aFont;
}
// =======================================================================
@ -758,7 +781,8 @@ Handle(Font_SystemFont) Font_FontMgr::FindFallbackFont (Font_UnicodeSubset theSu
// =======================================================================
Handle(Font_SystemFont) Font_FontMgr::FindFont (const TCollection_AsciiString& theFontName,
Font_StrictLevel theStrictLevel,
Font_FontAspect& theFontAspect) const
Font_FontAspect& theFontAspect,
Standard_Boolean theDoFailMsg) const
{
TCollection_AsciiString aFontName (theFontName);
aFontName.LowerCase();
@ -844,7 +868,10 @@ Handle(Font_SystemFont) Font_FontMgr::FindFont (const TCollection_AsciiString& t
}
if (aFont.IsNull())
{
Message::DefaultMessenger()->Send (TCollection_AsciiString("Font_FontMgr, error: unable to find any font!", Message_Fail));
if (theDoFailMsg)
{
Message::DefaultMessenger()->Send (TCollection_AsciiString("Font_FontMgr, error: unable to find any font!"), Message_Fail);
}
return Handle(Font_SystemFont)();
}

View File

@ -100,9 +100,11 @@ public:
//! @param theStrictLevel [in] search strict level for using aliases and fallback
//! @param theFontAspect [in] [out] font aspect to find (considered only if family name is not found);
//! can be modified if specified font alias refers to another style (compatibility with obsolete aliases)
//! @param theDoFailMsg [in] put error message on failure into default messenger
Standard_EXPORT Handle(Font_SystemFont) FindFont (const TCollection_AsciiString& theFontName,
Font_StrictLevel theStrictLevel,
Font_FontAspect& theFontAspect) const;
Font_FontAspect& theFontAspect,
Standard_Boolean theDoFailMsg = Standard_True) const;
//! Tries to find font by given parameters.
Handle(Font_SystemFont) FindFont (const TCollection_AsciiString& theFontName,
@ -133,13 +135,16 @@ public:
//! Can be disabled to avoid redundant messages with Message_Trace level.
void SetTraceAliases (Standard_Boolean theToTrace) { myToTraceAliases = theToTrace; }
//! Collects available fonts paths.
Standard_EXPORT void InitFontDataBase();
//! Clear registry. Can be used for testing purposes.
Standard_EXPORT void ClearFontDataBase();
private:
//! Creates empty font manager object
Standard_EXPORT Font_FontMgr();
//! Collects available fonts paths.
Standard_EXPORT void InitFontDataBase();
private:

View File

@ -5528,6 +5528,14 @@ static int VFont (Draw_Interpretor& theDI,
theArgVec + anArgIter + 1,
aStrictLevel);
}
else if (anArgCase == "-clear")
{
aMgr->ClearFontDataBase();
}
else if (anArgCase == "-init")
{
aMgr->InitFontDataBase();
}
else if (anArgIter + 1 < theArgNb
&& (anArgCase == "-find"
|| anArgCase == "find"))
@ -6600,7 +6608,8 @@ void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands)
theCommands.Add ("vfont",
"vfont [-add pathToFont [fontName] [regular,bold,italic,boldItalic=undefined] [singleStroke]]"
"\n\t\t: [-strict {any|aliases|strict}] [-find fontName [regular,bold,italic,boldItalic=undefined]] [-verbose {on|off}]"
"\n\t\t: [-unicodeFallback {on|off}]",
"\n\t\t: [-unicodeFallback {on|off}]"
"\n\t\t: [-clear] [-init]",
__FILE__, VFont, group);
theCommands.Add ("vvertexmode",

27
tests/3rdparty/fonts/C3 vendored Normal file
View File

@ -0,0 +1,27 @@
puts "================"
puts "0031079: Visualization - embed minimal fallback font"
puts "================"
puts ""
puts "REQUIRED All: Font_FontMgr, error: unable to find any font!"
puts "REQUIRED All: Font_FontMgr, error: unable to find Western fallback font!"
dtracelevel trace
pload VISUALIZATION
vfont -verbose 1
vfont -clear
# print empty list
vfont
vclear
vinit View1
vpoint p0 0 0 0
vviewcube vc
vdrawtext t "My Text, он мой!" -font "UNKNOWN" -aspect italic -pos 0 0 0 -2d -persPos -1 1 30
text2brep b "My Text, он мой!" -font "UNKNOWN" -aspect italic
vtop
vdisplay -dispMode 1 b
vfit
vdump $imagedir/${casename}.png

View File

@ -1 +0,0 @@
SKIPPED /test skipped/ GL2PS is absent