From 7f82b6c60ca817a8d2ea184a484099e35ca1d924 Mon Sep 17 00:00:00 2001 From: Joseph Argento Date: Thu, 17 Apr 2025 08:37:04 -0500 Subject: [PATCH] Limit char quad matching. QA noticed for a particular document viewing it caused an out of bounds exception. This is a legacy viewer sample which had a lot of things crammed into it. In this case text highlighting isn't quite handling unicode correctly but we have dedicated Text samples for showing how to work with the WordFinder so let's just make sure the text size and # of quads match up to prevent this problem from happening. --- Display/DotNETViewerComponent/DotNETView.cs | 39 +++++++++++---------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/Display/DotNETViewerComponent/DotNETView.cs b/Display/DotNETViewerComponent/DotNETView.cs index 43782d9..61bec1f 100644 --- a/Display/DotNETViewerComponent/DotNETView.cs +++ b/Display/DotNETViewerComponent/DotNETView.cs @@ -906,33 +906,36 @@ private IList GetPageQuads(int pageNum) bool letter = false; Quad q = null; IList charQuads = word.CharQuads; - for (int i = 0; i < text.Length; ++i) + if (charQuads.Count == text.Length) { - if (char.IsLetter(text, i) != letter) - { - if (q != null) quads.Add(q); - q = null; - letter = !letter; - } - if (q == null) - { - q = Utils.Clone(charQuads[i]); - } - else // check distance between quads - if we can concat them or not + for (int i = 0; i < text.Length; ++i) { - const double interval = 0.5; - if (q.BottomRight.H + interval < charQuads[i].BottomLeft.H) + if (char.IsLetter(text, i) != letter) + { + if (q != null) quads.Add(q); + q = null; + letter = !letter; + } + if (q == null) { - quads.Add(q); q = Utils.Clone(charQuads[i]); } - else + else // check distance between quads - if we can concat them or not { - q = Concat(q, charQuads[i]); + const double interval = 0.5; + if (q.BottomRight.H + interval < charQuads[i].BottomLeft.H) + { + quads.Add(q); + q = Utils.Clone(charQuads[i]); + } + else + { + q = Concat(q, charQuads[i]); + } } } } - if (q != null) quads.Add(q); + if (q != null) quads.Add(q); } } if (quads.Count > 0) return quads;