diff options
author | kamel5 <vdr.kamel5 (at) gmx (dot) net> | 2020-01-08 16:17:08 +0100 |
---|---|---|
committer | kamel5 <vdr.kamel5 (at) gmx (dot) net> | 2020-01-09 14:29:30 +0100 |
commit | ffd3e2c79f22e04ddf5f6710e5f3606c6c58dd34 (patch) | |
tree | dfb621812e65c234cdaa786a9ff67b71683c8783 /tools.c | |
parent | c77f74321fcfc88a81513184797c03850f105840 (diff) | |
download | vdr-plugin-tvguide-ffd3e2c79f22e04ddf5f6710e5f3606c6c58dd34.tar.gz vdr-plugin-tvguide-ffd3e2c79f22e04ddf5f6710e5f3606c6c58dd34.tar.bz2 |
Refactor CutText in horizontal epgview
Diffstat (limited to 'tools.c')
-rw-r--r-- | tools.c | 36 |
1 files changed, 14 insertions, 22 deletions
@@ -24,31 +24,23 @@ cPlugin *GetScraperPlugin(void) { * CUTTEXT ****************************************************************************************/ std::string CutText(std::string text, int width, const cFont *font) { - if (width <= font->Size()) + int actWidth = font->Width(text.c_str()); + if (actWidth <= width) { return text.c_str(); - if (font->Width(text.c_str()) < width) - return text.c_str(); - cTextWrapper twText; - twText.Set(text.c_str(), font, width); - std::string cuttedTextNative = twText.GetLine(0); - std::stringstream sstrText; - sstrText << cuttedTextNative << "..."; - std::string cuttedText = sstrText.str(); - int actWidth = font->Width(cuttedText.c_str()); - if (actWidth > width) { - int overlap = actWidth - width; - int charWidth = font->Width("."); - if (charWidth == 0) - charWidth = 1; - int cutChars = overlap / charWidth; - if (cutChars > 0) { - cuttedTextNative = cuttedTextNative.substr(0, cuttedTextNative.length() - cutChars); - std::stringstream sstrText2; - sstrText2 << cuttedTextNative << "..."; - cuttedText = sstrText2.str(); + } else { + int i = std::max((actWidth - width) / font->Size(), 1); + do { + text = text.substr(0, text.length() - i); + std::stringstream sstrText; + sstrText << text << "...."; + actWidth = font->Width(sstrText.str().c_str()); + i = 1; } + while ((actWidth > width) && (text.length() > 0)); + std::stringstream sstrText2; + sstrText2 << text << "..."; + return sstrText2.str(); } - return cuttedText; } /**************************************************************************************** |