Skip to content

Commit a500b26

Browse files
authored
Fix Font not displaying properly due to change in UTF8 (#3206)
1 parent 316f6e9 commit a500b26

File tree

1 file changed

+16
-9
lines changed
  • src/nanoFramework.Graphics/Graphics/Core/Support/Fonts

1 file changed

+16
-9
lines changed

src/nanoFramework.Graphics/Graphics/Core/Support/Fonts/Font.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,13 @@ HRESULT CLR_GFX_Font::CreateInstance(CLR_RT_HeapBlock &ref, const CLR_UINT8 *dat
9797
bm = (const CLR_GFX_BitmapDescription *)data;
9898
data += sizeof(CLR_GFX_BitmapDescription);
9999

100-
NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_BinaryBlob::CreateInstance(
101-
ref,
102-
sizeof(CLR_GFX_Font),
103-
NULL,
104-
CLR_GFX_Font::RelocationHandler,
105-
CLR_RT_HeapBlock::HB_CompactOnFailure));
100+
NANOCLR_CHECK_HRESULT(
101+
CLR_RT_HeapBlock_BinaryBlob::CreateInstance(
102+
ref,
103+
sizeof(CLR_GFX_Font),
104+
NULL,
105+
CLR_GFX_Font::RelocationHandler,
106+
CLR_RT_HeapBlock::HB_CompactOnFailure));
106107

107108
blob = ref.DereferenceBinaryBlob();
108109
font = (CLR_GFX_Font *)blob->GetData();
@@ -155,16 +156,19 @@ int CLR_GFX_Font::StringOut(
155156
CLR_UINT16 buf[3];
156157
CLR_UINT32 nTotWidth = 0;
157158
CLR_GFX_FontCharacterInfo chr;
159+
CLR_UINT32 charLimit = (maxChars < 0) ? (CLR_UINT32)uh.CountNumberOfCharacters() : (CLR_UINT32)maxChars;
158160

159161
yPos += m_font.m_metrics.m_offset;
160162

161-
while (maxChars-- != 0)
163+
while (charLimit-- != 0)
162164
{
163165
uh.m_outputUTF16 = buf;
164166
uh.m_outputUTF16_size = MAXSTRLEN(buf);
165167

166168
if (uh.ConvertFromUTF8(1, false) == false)
169+
{
167170
break;
171+
}
168172

169173
CLR_UINT16 c = buf[0];
170174

@@ -325,13 +329,17 @@ void CLR_GFX_Font::CountCharactersInWidth(
325329
CLR_GFX_FontCharacterInfo chr;
326330
totWidth = 0;
327331
uh.SetInputUTF8(str);
328-
while (maxChars != 0)
332+
CLR_UINT32 charLimit = (maxChars < 0) ? (CLR_UINT32)uh.CountNumberOfCharacters() : (CLR_UINT32)maxChars;
333+
334+
while (charLimit-- > 0)
329335
{
330336
uh.m_outputUTF16 = buf;
331337
uh.m_outputUTF16_size = MAXSTRLEN(buf);
332338

333339
if (uh.ConvertFromUTF8(1, false) == false)
340+
{
334341
break;
342+
}
335343

336344
CLR_UINT16 c = buf[0];
337345
bool fNewLine = (c == '\n');
@@ -385,7 +393,6 @@ void CLR_GFX_Font::CountCharactersInWidth(
385393
totWidth += chrWidth;
386394

387395
str = (LPCSTR)uh.m_inputUTF8;
388-
maxChars--;
389396
num++;
390397

391398
// Break @ hyphens

0 commit comments

Comments
 (0)