From dda8a36ee275c91415f3b345a601cd3f535e97a8 Mon Sep 17 00:00:00 2001 From: Nimetu Date: Tue, 8 Jan 2019 11:31:50 +0200 Subject: [PATCH] Changed: Allow to set custom sizing chars for text --HG-- branch : develop --- code/nel/include/nel/gui/view_text.h | 6 +++ code/nel/src/gui/view_text.cpp | 69 ++++++++++++++++++++++------ 2 files changed, 62 insertions(+), 13 deletions(-) diff --git a/code/nel/include/nel/gui/view_text.h b/code/nel/include/nel/gui/view_text.h index aa1d83330..b9ef7211c 100644 --- a/code/nel/include/nel/gui/view_text.h +++ b/code/nel/include/nel/gui/view_text.h @@ -100,6 +100,9 @@ namespace NLGUI void setMultiMaxLine(uint l) { _MultiMaxLine = 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 void enableStringSelection(uint start, uint end); void disableStringSelection(); @@ -244,6 +247,9 @@ namespace NLGUI bool _Oblique; // width of the font in pixel. Just a Hint for tabing format (computed with '_') float _FontWidth; + // strings to use when computing font size + ucstring _FontSizingChars; + ucstring _FontSizingFallback; // height of the font in pixel. // use getFontHeight float _FontHeight; diff --git a/code/nel/src/gui/view_text.cpp b/code/nel/src/gui/view_text.cpp index 8d36c046d..03dd52701 100644 --- a/code/nel/src/gui/view_text.cpp +++ b/code/nel/src/gui/view_text.cpp @@ -97,7 +97,6 @@ namespace NLGUI _InvalidTextContext= true; _FirstLineX = 0; - computeFontSize (); _SingleLineTextClamped= false; _OverExtendViewText= false; @@ -110,6 +109,14 @@ namespace NLGUI _LetterColors = NULL; _Setuped= false; _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 ); } + else + if ( name == "sizing_chars" ) + { + return _FontSizingChars.toUtf8(); + } + else + if ( name == "sizing_fallback" ) + { + return _FontSizingFallback.toUtf8(); + } else return ""; } @@ -615,6 +632,18 @@ namespace NLGUI return true; } + else + if( name == "sizing_chars" ) + { + _FontSizingChars.fromUtf8(value); + return true; + } + else + if( name == "sizing_fallback" ) + { + _FontSizingFallback.fromUtf8(value); + return true; + } else return false; } @@ -679,6 +708,8 @@ namespace NLGUI 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 "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; } @@ -854,6 +885,17 @@ namespace NLGUI _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 (); } @@ -1325,6 +1367,15 @@ namespace NLGUI _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) { @@ -2856,22 +2907,14 @@ namespace NLGUI TextContext->setOblique (_Oblique); // Letter size - ucstring chars; - // 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); + UTextContext::CStringInfo si = TextContext->getStringInfo(_FontSizingChars); // font generator changes unknown glyphs to dot '.'. use fallback if it looks odd if (_FontSize > (si.StringHeight + si.StringLine)) { - chars.fromUtf8("|"); - si = TextContext->getStringInfo(chars); + si = TextContext->getStringInfo(_FontSizingFallback); } + // add a padding of 1 pixel else the top will be truncated _FontHeight = si.StringHeight + 1; _FontLegHeight = si.StringLine; @@ -2880,7 +2923,7 @@ namespace NLGUI si = TextContext->getStringInfo(ucstring(" ")); _SpaceWidth = si.StringWidth; - // Font Width + // Font Width (used for ) si = TextContext->getStringInfo(ucstring("_")); _FontWidth = si.StringWidth; }