Changed: Allow to set custom sizing chars for text
--HG-- branch : develop
This commit is contained in:
parent
bc35724622
commit
dda8a36ee2
2 changed files with 62 additions and 13 deletions
|
@ -100,6 +100,9 @@ namespace NLGUI
|
||||||
void setMultiMaxLine(uint l) { _MultiMaxLine = l; }
|
void setMultiMaxLine(uint l) { _MultiMaxLine = l; }
|
||||||
void setMultiMinLine(uint l) { _MultiMinLine = l; }
|
void setMultiMinLine(uint l) { _MultiMinLine = l; }
|
||||||
|
|
||||||
|
// Override chars used to compute font size
|
||||||
|
void setFontSizing(const std::string &chars, const std::string &fallback);
|
||||||
|
|
||||||
// Force only a subset of letter to be displayed. Default is 0/0xFFFFFFFF
|
// Force only a subset of letter to be displayed. Default is 0/0xFFFFFFFF
|
||||||
void enableStringSelection(uint start, uint end);
|
void enableStringSelection(uint start, uint end);
|
||||||
void disableStringSelection();
|
void disableStringSelection();
|
||||||
|
@ -244,6 +247,9 @@ namespace NLGUI
|
||||||
bool _Oblique;
|
bool _Oblique;
|
||||||
// width of the font in pixel. Just a Hint for tabing format (computed with '_')
|
// width of the font in pixel. Just a Hint for tabing format (computed with '_')
|
||||||
float _FontWidth;
|
float _FontWidth;
|
||||||
|
// strings to use when computing font size
|
||||||
|
ucstring _FontSizingChars;
|
||||||
|
ucstring _FontSizingFallback;
|
||||||
// height of the font in pixel.
|
// height of the font in pixel.
|
||||||
// use getFontHeight
|
// use getFontHeight
|
||||||
float _FontHeight;
|
float _FontHeight;
|
||||||
|
|
|
@ -97,7 +97,6 @@ namespace NLGUI
|
||||||
|
|
||||||
_InvalidTextContext= true;
|
_InvalidTextContext= true;
|
||||||
_FirstLineX = 0;
|
_FirstLineX = 0;
|
||||||
computeFontSize ();
|
|
||||||
|
|
||||||
_SingleLineTextClamped= false;
|
_SingleLineTextClamped= false;
|
||||||
_OverExtendViewText= false;
|
_OverExtendViewText= false;
|
||||||
|
@ -110,6 +109,14 @@ namespace NLGUI
|
||||||
_LetterColors = NULL;
|
_LetterColors = NULL;
|
||||||
_Setuped= false;
|
_Setuped= false;
|
||||||
_AutoClampOffset = 0;
|
_AutoClampOffset = 0;
|
||||||
|
|
||||||
|
// Letter size
|
||||||
|
// - "_" that should be the character with the lowest part
|
||||||
|
// - A with an accent for the highest part
|
||||||
|
_FontSizingChars.fromUtf8("_\xc3\x84");
|
||||||
|
// fallback if SizingChars are not supported by font
|
||||||
|
_FontSizingFallback.fromUtf8("|");
|
||||||
|
computeFontSize ();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
|
@ -370,6 +377,16 @@ namespace NLGUI
|
||||||
{
|
{
|
||||||
return toString( _ContinuousUpdate );
|
return toString( _ContinuousUpdate );
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
if ( name == "sizing_chars" )
|
||||||
|
{
|
||||||
|
return _FontSizingChars.toUtf8();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if ( name == "sizing_fallback" )
|
||||||
|
{
|
||||||
|
return _FontSizingFallback.toUtf8();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -615,6 +632,18 @@ namespace NLGUI
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
if( name == "sizing_chars" )
|
||||||
|
{
|
||||||
|
_FontSizingChars.fromUtf8(value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if( name == "sizing_fallback" )
|
||||||
|
{
|
||||||
|
_FontSizingFallback.fromUtf8(value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -679,6 +708,8 @@ namespace NLGUI
|
||||||
xmlSetProp( node, BAD_CAST "clamp_right", BAD_CAST toString( _ClampRight ).c_str() );
|
xmlSetProp( node, BAD_CAST "clamp_right", BAD_CAST toString( _ClampRight ).c_str() );
|
||||||
xmlSetProp( node, BAD_CAST "auto_clamp_offset", BAD_CAST toString( _AutoClampOffset ).c_str() );
|
xmlSetProp( node, BAD_CAST "auto_clamp_offset", BAD_CAST toString( _AutoClampOffset ).c_str() );
|
||||||
xmlSetProp( node, BAD_CAST "continuous_update", BAD_CAST toString( _ContinuousUpdate ).c_str() );
|
xmlSetProp( node, BAD_CAST "continuous_update", BAD_CAST toString( _ContinuousUpdate ).c_str() );
|
||||||
|
xmlSetProp( node, BAD_CAST "sizing_chars", BAD_CAST _FontSizingChars.toUtf8().c_str() );
|
||||||
|
xmlSetProp( node, BAD_CAST "sizing_fallback", BAD_CAST _FontSizingFallback.toUtf8().c_str() );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -854,6 +885,17 @@ namespace NLGUI
|
||||||
_ContinuousUpdate = convertBool(prop);
|
_ContinuousUpdate = convertBool(prop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// "_Ä" lowest/highest chars (underscore, A+diaeresis)
|
||||||
|
_FontSizingChars.fromUtf8("_\xc3\x84");
|
||||||
|
prop = (char*) xmlGetProp( cur, (xmlChar*)"sizing_chars" );
|
||||||
|
if (prop)
|
||||||
|
_FontSizingChars.fromUtf8((const char*)prop);
|
||||||
|
|
||||||
|
// fallback if SizingChars are not supported by font
|
||||||
|
_FontSizingFallback.fromUtf8("|");
|
||||||
|
prop = (char*) xmlGetProp( cur, (xmlChar*)"sizing_fallback" );
|
||||||
|
if (prop)
|
||||||
|
_FontSizingFallback.fromUtf8((const char*)prop);
|
||||||
|
|
||||||
computeFontSize ();
|
computeFontSize ();
|
||||||
}
|
}
|
||||||
|
@ -1325,6 +1367,15 @@ namespace NLGUI
|
||||||
_FormatTags.clear();
|
_FormatTags.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ***************************************************************************
|
||||||
|
void CViewText::setFontSizing(const std::string &chars, const std::string &fallback)
|
||||||
|
{
|
||||||
|
_FontSizingChars.clear();
|
||||||
|
_FontSizingChars.fromUtf8(chars);
|
||||||
|
_FontSizingFallback.clear();
|
||||||
|
_FontSizingFallback.fromUtf8(fallback);
|
||||||
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
void CViewText::setFontName(const std::string &name)
|
void CViewText::setFontName(const std::string &name)
|
||||||
{
|
{
|
||||||
|
@ -2856,22 +2907,14 @@ namespace NLGUI
|
||||||
TextContext->setOblique (_Oblique);
|
TextContext->setOblique (_Oblique);
|
||||||
|
|
||||||
// Letter size
|
// Letter size
|
||||||
ucstring chars;
|
UTextContext::CStringInfo si = TextContext->getStringInfo(_FontSizingChars);
|
||||||
// instead of using the height of "|" that depends on font,
|
|
||||||
// we're using 2 characters:
|
|
||||||
// - "_" that should be the character with the lowest part
|
|
||||||
// - A with an accent for the highest part
|
|
||||||
chars.fromUtf8("_\xc3\x84");
|
|
||||||
|
|
||||||
// for now we can't know that directly from UTextContext
|
|
||||||
UTextContext::CStringInfo si = TextContext->getStringInfo(chars);
|
|
||||||
|
|
||||||
// font generator changes unknown glyphs to dot '.'. use fallback if it looks odd
|
// font generator changes unknown glyphs to dot '.'. use fallback if it looks odd
|
||||||
if (_FontSize > (si.StringHeight + si.StringLine))
|
if (_FontSize > (si.StringHeight + si.StringLine))
|
||||||
{
|
{
|
||||||
chars.fromUtf8("|");
|
si = TextContext->getStringInfo(_FontSizingFallback);
|
||||||
si = TextContext->getStringInfo(chars);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// add a padding of 1 pixel else the top will be truncated
|
// add a padding of 1 pixel else the top will be truncated
|
||||||
_FontHeight = si.StringHeight + 1;
|
_FontHeight = si.StringHeight + 1;
|
||||||
_FontLegHeight = si.StringLine;
|
_FontLegHeight = si.StringLine;
|
||||||
|
@ -2880,7 +2923,7 @@ namespace NLGUI
|
||||||
si = TextContext->getStringInfo(ucstring(" "));
|
si = TextContext->getStringInfo(ucstring(" "));
|
||||||
_SpaceWidth = si.StringWidth;
|
_SpaceWidth = si.StringWidth;
|
||||||
|
|
||||||
// Font Width
|
// Font Width (used for <tab>)
|
||||||
si = TextContext->getStringInfo(ucstring("_"));
|
si = TextContext->getStringInfo(ucstring("_"));
|
||||||
_FontWidth = si.StringWidth;
|
_FontWidth = si.StringWidth;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue