-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from JetBrains/fix-ligatures-cursor
Fix cursor position in ligatures
- Loading branch information
Showing
4 changed files
with
60 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ on: | |
default: 'false' | ||
|
||
env: | ||
version: m99-f85ab491eb | ||
version: m99-f85ab491eb-2 | ||
|
||
jobs: | ||
macos: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
patches/Fix_glyph_position_and_rects_for_chars_inside_ligatures.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
Index: modules/skparagraph/src/TextLine.cpp | ||
IDEA additional info: | ||
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | ||
<+>UTF-8 | ||
=================================================================== | ||
diff --git a/modules/skparagraph/src/TextLine.cpp b/modules/skparagraph/src/TextLine.cpp | ||
--- a/modules/skparagraph/src/TextLine.cpp (revision f85ab491eb97b54d0bfeac19fed27feb499b8912) | ||
+++ b/modules/skparagraph/src/TextLine.cpp (date 1646928189139) | ||
@@ -615,6 +615,7 @@ | ||
} | ||
return result; | ||
} | ||
+ TextRange origTextRange = textRange; | ||
// Find [start:end] clusters for the text | ||
Cluster* start = nullptr; | ||
Cluster* end = nullptr; | ||
@@ -688,8 +689,8 @@ | ||
// TODO: This is where we get smart about selecting a part of a cluster | ||
// by shaping each grapheme separately and then use the result sizes | ||
// to calculate the proportions | ||
- auto leftCorrection = start->sizeToChar(textRange.start); | ||
- auto rightCorrection = end->sizeFromChar(textRange.end - 1); | ||
+ auto leftCorrection = start->sizeToChar(origTextRange.start); | ||
+ auto rightCorrection = end->sizeFromChar(origTextRange.end - 1); | ||
result.clip.fLeft += leftCorrection; | ||
result.clip.fRight -= rightCorrection; | ||
result.clippingNeeded = leftCorrection != 0 || rightCorrection != 0; | ||
@@ -1248,6 +1249,27 @@ | ||
auto clusterIndex8 = context.run->globalClusterIndex(found); | ||
auto clusterEnd8 = context.run->globalClusterIndex(found + 1); | ||
|
||
+ size_t charsInCluster = 0; | ||
+ for (auto i = clusterIndex8; i < clusterEnd8; i++) { | ||
+ i = run->owner()->findNextGraphemeBoundary(i); | ||
+ if (i < clusterEnd8) charsInCluster++; | ||
+ } | ||
+ | ||
+ // Calculate offset for a character inside a ligature (e.g. ff or ffi) | ||
+ // Considering all characters in the ligature have equal width | ||
+ if (glyphemePosWidth > 0 && charsInCluster > 1) { | ||
+ glyphemePosWidth /= charsInCluster; | ||
+ size_t charIndexInCluster = std::floor((dx - glyphemePosLeft) / glyphemePosWidth); | ||
+ if (!context.run->leftToRight()) { | ||
+ charIndexInCluster = charsInCluster - charIndexInCluster; | ||
+ } | ||
+ glyphemePosLeft += charIndexInCluster * glyphemePosWidth; | ||
+ for (size_t i = 0; i < charIndexInCluster; i++) { | ||
+ clusterIndex8 = run->owner()->findNextGraphemeBoundary(clusterIndex8 + 1); | ||
+ } | ||
+ clusterEnd8 = run->owner()->findNextGraphemeBoundary(clusterIndex8 + 1); | ||
+ } | ||
+ | ||
SkScalar center = glyphemePosLeft + glyphemePosWidth / 2; | ||
if ((dx < center) == context.run->leftToRight()) { | ||
size_t utf16Index = context.run->leftToRight() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#!/bin/bash | ||
ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"/.. | ||
OLDVER=m99-51988d0bc1 | ||
NEWVER=m99-f85ab491eb | ||
OLDVER=m99-f85ab491eb | ||
NEWVER=m99-f85ab491eb-2 | ||
find -E $ROOT/script *.md .github -regex '.*\.(py|md|yml)' -exec sed -i '' -e "s/$OLDVER/$NEWVER/g" {} \; |