diff --git a/uppsrc/CtrlLib/LineEdit.cpp b/uppsrc/CtrlLib/LineEdit.cpp index 5b36daa41..b528c5b11 100644 --- a/uppsrc/CtrlLib/LineEdit.cpp +++ b/uppsrc/CtrlLib/LineEdit.cpp @@ -71,8 +71,7 @@ LineEdit& LineEdit::SetFont(Font f) { } Size LineEdit::GetFontSize() const { - FontInfo fi = font.Info(); - return Size(max(fi['M'], fi['W']), fi.GetHeight()); + return Size(font.GetMonoWidth(), font.GetHeight()); } void LineEdit::SetRectSelection(int64 anchor, int64 cursor) diff --git a/uppsrc/Draw/Draw.h b/uppsrc/Draw/Draw.h index 959adcd2b..2b9a56007 100644 --- a/uppsrc/Draw/Draw.h +++ b/uppsrc/Draw/Draw.h @@ -162,6 +162,7 @@ public: int GetOverhang() const { return Fi().overhang; } int GetAveWidth() const { return Fi().avewidth; } int GetMaxWidth() const { return Fi().maxwidth; } + int GetMonoWidth() const { return max(GetWidth('M'), GetWidth('W')); } bool IsNormal(int ch) const; bool IsComposed(int ch) const; bool IsReplaced(int ch) const; diff --git a/uppsrc/Draw/src.tpp/Font_en-us.tpp b/uppsrc/Draw/src.tpp/Font_en-us.tpp index 2689e8aee..0d720fabe 100644 --- a/uppsrc/Draw/src.tpp/Font_en-us.tpp +++ b/uppsrc/Draw/src.tpp/Font_en-us.tpp @@ -276,11 +276,26 @@ of text.&] [s3; &] [s4; &] [s5;:Font`:`:GetAveWidth`(`)const: [@(0.0.255) int]_[* GetAveWidth]()_[@(0.0.255) const]&] -[s2;%% Returns the average width of character.&] +[s2;%% Returns the average width of character. Depends on information +from the font provider, which is not always reliable `- it is +better the obtain the spacing info from the width of individual +glyphs.&] [s3; &] [s4; &] [s5;:Font`:`:GetMaxWidth`(`)const: [@(0.0.255) int]_[* GetMaxWidth]()_[@(0.0.255) const]&] -[s2;%% Returns the maximal width of character.&] +[s2;%% Returns the maximal width of character. Depends on information +from the font provider, which is not always reliable `- it is +better the obtain the spacing info from the width of individual +glyphs.&] +[s3; &] +[s4; &] +[s5;:Upp`:`:Font`:`:GetMonoWidth`(`)const: [@(0.0.255) int]_[* GetMonoWidth]()_[@(0.0.255) c +onst]&] +[s2;%% Returns supposed width of character cell if the font is (or +is considered) monospace. This is the method used in LineEdit +to determine cell width. Currently, max(GetWidth(`'M`'), GetWidth(`'W`')) +value is used as GetAveWidth and GetMaxWidth using the information +from the font metadata is unreliable.&] [s3; &] [s4; &] [s5;:Font`:`:IsNormal`(int`)const: [@(0.0.255) bool]_[* IsNormal]([@(0.0.255) int]_[@3 ch])_[@(0.0.255) c diff --git a/uppsrc/TextDiffCtrl/TextCtrl.cpp b/uppsrc/TextDiffCtrl/TextCtrl.cpp index 491e5810e..663bc1bbd 100644 --- a/uppsrc/TextDiffCtrl/TextCtrl.cpp +++ b/uppsrc/TextDiffCtrl/TextCtrl.cpp @@ -391,12 +391,10 @@ void TextCompareCtrl::SetFont(Font f, Font nf) { font = f; number_font = nf; - FontInfo fi = f.Info(); - FontInfo ni = nf.Info(); - letter.cy = fi.GetHeight(); - letter.cx = fi.GetAveWidth(); - number_width = 5 * ni.GetAveWidth(); - number_yshift = (fi.GetHeight() - ni.GetHeight() + 2) >> 1; + letter.cy = f.GetHeight(); + letter.cx = f.GetMonoWidth(); + number_width = 5 * nf.GetMonoWidth(); + number_yshift = (f.GetHeight() - nf.GetHeight() + 2) >> 1; Layout(); } diff --git a/uppsrc/ide/Console.cpp b/uppsrc/ide/Console.cpp index 42d32ffa3..747b87b2e 100644 --- a/uppsrc/ide/Console.cpp +++ b/uppsrc/ide/Console.cpp @@ -58,7 +58,7 @@ void Console::Append(const String& s) { SetEditable(); MoveTextEnd(); WString t = Filter(s, sAppf).ToWString(); - int mg = max(40, sb.GetReducedViewSize().cx / GetFont().GetAveWidth()); + int mg = max(40, sb.GetReducedViewSize().cx / GetFontSize().cx); if(wrap_text && mg > 4) { int x = GetColumnLine(GetCursor32()).x; WStringBuffer tt;