Skip to content

Commit

Permalink
fix(windows): check font count display none found
Browse files Browse the repository at this point in the history
This change is to check number of fonts found for keyboard
to guard against trying to index it when there are no fonts.
  for i := 0 to grid.RowCount - 1 do
        m := System.Math.Max(m,
	Canvas.TextWidth(FSelectedKeyboard.Fonts[i].FontName) + 6)
It also notifies the user no suggested fonts where found.
  • Loading branch information
rc-swag committed Apr 22, 2024
1 parent f199c6a commit 94c8879
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 34 deletions.
5 changes: 4 additions & 1 deletion windows/src/desktop/kmshell/xml/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,10 @@ keyboard that you use in Windows. Keyman keyboards will adapt automatically to
<!-- Introduced: 8.0.294.0 -->
<string name="S_OSK_FontHelper_ChooseKeyboard" comment="OSK Font helper choose keyboard">Please select a Keyman keyboard to find related fonts.</string>


<!-- Context: OSK Font Helper -->
<!-- String Type: FormatString -->
<!-- Introduced: 17.0.312.0 -->
<string name="S_OSK_FontHelper_NoFonts" comment="OSK Font helper no fonts found for keyboard">No fonts have been found as suggestions for Keyboard %1$s .</string>

<!-- Context: Text Editor -->
<!-- String Type: FormatString -->
Expand Down
74 changes: 41 additions & 33 deletions windows/src/engine/keyman/viskbd/UfrmOSKFontHelper.pas
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
(*
Name: UfrmOSKFontHelper
Copyright: Copyright (C) SIL International.
Documentation:
Description:
Documentation:
Description:
Create Date: 27 Mar 2008
Modified Date: 25 Sep 2014
Authors: mcdurdin
Related Files:
Dependencies:
Related Files:
Dependencies:
Bugs:
Todo:
Notes:
Bugs:
Todo:
Notes:
History: 27 Mar 2008 - mcdurdin - Initial version I1374
20 Jul 2008 - mcdurdin - I1533 - Show hint for non-Unicode keyboards
29 Mar 2010 - mcdurdin - I2199 - Shift+click
Expand Down Expand Up @@ -447,39 +447,47 @@ procedure TfrmOSKFontHelper.DisplayKeyboardFonts;
FKeyboard := FCheckFontKeyboards.Keyboards[FLastSelectedKeyboardID];
if (FLastSelectedKeyboardID <> '') and Assigned(FKeyboard) then
begin
SetLength(FChars, Length(FKeyboard.Chars));
J := 0;
I := 1;
while I <= Length(FKeyboard.Chars) do // I2712
if FKeyboard.Fonts.Count > 0 then
begin
ch := FKeyboard.Chars[I];
if Uni_IsSurrogate1(ch) and (I < Length(FKeyboard.Chars)) and Uni_IsSurrogate2(FKeyboard.Chars[I+1]) then
SetLength(FChars, Length(FKeyboard.Chars));
J := 0;
I := 1;
while I <= Length(FKeyboard.Chars) do // I2712
begin
ch2 := FKeyboard.Chars[I+1];
FChars[J] := Uni_SurrogateToUTF32(ch, ch2);
ch := FKeyboard.Chars[I];
if Uni_IsSurrogate1(ch) and (I < Length(FKeyboard.Chars)) and Uni_IsSurrogate2(FKeyboard.Chars[I+1]) then
begin
ch2 := FKeyboard.Chars[I+1];
FChars[J] := Uni_SurrogateToUTF32(ch, ch2);
Inc(I);
end
else
FChars[J] := Ord(ch);
Inc(I);
end
else
FChars[J] := Ord(ch);
Inc(I);
Inc(J);
end;
Inc(J);
end;

SetLength(FChars, J);
SetLength(FChars, J);

grid.ColCount := Length(FChars) + 2;
grid.RowCount := FKeyboard.Fonts.Count;
grid.ColCount := Length(FChars) + 2;
grid.RowCount := FKeyboard.Fonts.Count;

for i := 0 to FKeyboard.Fonts.Count - 1 do
if FKeyboard.Fonts[i].Coverage < 50 then
begin
grid.RowCount := i;
Break;
end;
for i := 0 to FKeyboard.Fonts.Count - 1 do
if FKeyboard.Fonts[i].Coverage < 50 then
begin
grid.RowCount := i;
Break;
end;

FSelectedKeyboard := FKeyboard;
FormatGrid;
SetDisplay('');
FSelectedKeyboard := FKeyboard;
FormatGrid;
SetDisplay('');
end
else
begin
FSelectedKeyboard := FKeyboard;
SetDisplay(MsgFromIdFormat(S_OSK_FontHelper_NoFonts, [FSelectedKeyboard.Name]));
end;
end
else
begin
Expand Down

0 comments on commit 94c8879

Please sign in to comment.