From 94c88799610148f83fcca7013baaf3e8a57d4dc4 Mon Sep 17 00:00:00 2001 From: rc-swag <58423624+rc-swag@users.noreply.github.com> Date: Mon, 22 Apr 2024 17:01:44 +1000 Subject: [PATCH 1/3] fix(windows): check font count display none found 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. --- windows/src/desktop/kmshell/xml/strings.xml | 5 +- .../keyman/viskbd/UfrmOSKFontHelper.pas | 78 ++++++++++--------- 2 files changed, 47 insertions(+), 36 deletions(-) diff --git a/windows/src/desktop/kmshell/xml/strings.xml b/windows/src/desktop/kmshell/xml/strings.xml index 2fa2307a33..8f7202dbdf 100644 --- a/windows/src/desktop/kmshell/xml/strings.xml +++ b/windows/src/desktop/kmshell/xml/strings.xml @@ -1186,7 +1186,10 @@ keyboard that you use in Windows. Keyman keyboards will adapt automatically to Please select a Keyman keyboard to find related fonts. - + + + + No fonts have been found as suggestions for Keyboard %1$s . diff --git a/windows/src/engine/keyman/viskbd/UfrmOSKFontHelper.pas b/windows/src/engine/keyman/viskbd/UfrmOSKFontHelper.pas index 02da0309ce..fd2c82e8f4 100644 --- a/windows/src/engine/keyman/viskbd/UfrmOSKFontHelper.pas +++ b/windows/src/engine/keyman/viskbd/UfrmOSKFontHelper.pas @@ -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 @@ -447,39 +447,47 @@ begin 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; - - SetLength(FChars, J); - - 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; + Inc(J); end; - FSelectedKeyboard := FKeyboard; - FormatGrid; - SetDisplay(''); + SetLength(FChars, J); + + 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; + + FSelectedKeyboard := FKeyboard; + FormatGrid; + SetDisplay(''); + end + else + begin + FSelectedKeyboard := FKeyboard; + SetDisplay(MsgFromIdFormat(S_OSK_FontHelper_NoFonts, [FSelectedKeyboard.Name])); + end; end else begin From 71377c3754b6a9ed3fa8a8cc1e1b54ddf61ce2b0 Mon Sep 17 00:00:00 2001 From: rc-swag <58423624+rc-swag@users.noreply.github.com> Date: Tue, 23 Apr 2024 08:56:56 +1000 Subject: [PATCH 2/3] fix(windows): Still need to guard against out of bound index --- windows/src/engine/keyman/viskbd/UfrmOSKFontHelper.pas | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/windows/src/engine/keyman/viskbd/UfrmOSKFontHelper.pas b/windows/src/engine/keyman/viskbd/UfrmOSKFontHelper.pas index fd2c82e8f4..cefd0ce01a 100644 --- a/windows/src/engine/keyman/viskbd/UfrmOSKFontHelper.pas +++ b/windows/src/engine/keyman/viskbd/UfrmOSKFontHelper.pas @@ -413,6 +413,11 @@ var i: Integer; m: Integer; begin + if FSelectedKeyboard.Fonts.Count = 0 then + begin + Exit; // Exit as grid needs at least one font + end; + grid.DefaultColWidth := tbSize.Position; grid.DefaultRowHeight := tbSize.Position; From faa828d55aa399852ef23d9348a32e721de7445a Mon Sep 17 00:00:00 2001 From: rc-swag <58423624+rc-swag@users.noreply.github.com> Date: Tue, 23 Apr 2024 10:44:09 +1000 Subject: [PATCH 3/3] fix(windows): remove space before full stop --- windows/src/desktop/kmshell/xml/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/windows/src/desktop/kmshell/xml/strings.xml b/windows/src/desktop/kmshell/xml/strings.xml index 8f7202dbdf..11a8ef0229 100644 --- a/windows/src/desktop/kmshell/xml/strings.xml +++ b/windows/src/desktop/kmshell/xml/strings.xml @@ -1189,7 +1189,7 @@ keyboard that you use in Windows. Keyman keyboards will adapt automatically to - No fonts have been found as suggestions for Keyboard %1$s . + No fonts have been found as suggestions for Keyboard %1$s.