mirror of
https://github.com/penpot/penpot.git
synced 2025-07-23 09:17:20 +02:00
🐛 Fix problem with RTL texts
This commit is contained in:
parent
20211101b7
commit
fef69cb707
3 changed files with 15 additions and 16 deletions
|
@ -21,27 +21,21 @@ goog.scope(function () {
|
|||
return range.getClientRects();
|
||||
}
|
||||
|
||||
self.parse_text_nodes = function(parent, direction, textNode) {
|
||||
self.parse_text_nodes = function(parent, textNode) {
|
||||
const content = textNode.textContent;
|
||||
const textSize = content.length;
|
||||
const rtl = direction === "rtl";
|
||||
|
||||
let from = 0;
|
||||
let to = 0;
|
||||
let current = "";
|
||||
let result = [];
|
||||
let prevRect = null;
|
||||
|
||||
while (to < textSize) {
|
||||
const rects = getRangeRects(textNode, from, to + 1);
|
||||
|
||||
if (rects.length > 1) {
|
||||
let position;
|
||||
|
||||
if (rtl) {
|
||||
position = rects[1];
|
||||
} else {
|
||||
position = rects[0];
|
||||
}
|
||||
const position = prevRect;
|
||||
|
||||
result.push({
|
||||
node: parent,
|
||||
|
@ -53,6 +47,7 @@ goog.scope(function () {
|
|||
current = "";
|
||||
|
||||
} else {
|
||||
prevRect = rects[0];
|
||||
current += content[to];
|
||||
to = to + 1;
|
||||
}
|
||||
|
|
|
@ -18,13 +18,14 @@
|
|||
[parent-node direction text-node]
|
||||
|
||||
(letfn [(parse-entry [^js entry]
|
||||
{:node (.-node entry)
|
||||
:position (dom/bounding-rect->rect (.-position entry))
|
||||
:text (.-text entry)})]
|
||||
{:node (.-node entry)
|
||||
:position (dom/bounding-rect->rect (.-position entry))
|
||||
:text (.-text entry)
|
||||
:direction direction})]
|
||||
(into
|
||||
[]
|
||||
(map parse-entry)
|
||||
(tpd/parse-text-nodes parent-node direction text-node))))
|
||||
(tpd/parse-text-nodes parent-node text-node))))
|
||||
|
||||
|
||||
(defn calc-text-node-positions
|
||||
|
@ -75,7 +76,7 @@
|
|||
(let [text-data (calc-text-node-positions base-node viewport zoom)]
|
||||
(when (d/not-empty? text-data)
|
||||
(->> text-data
|
||||
(mapv (fn [{:keys [node position text]}]
|
||||
(mapv (fn [{:keys [node position text direction]}]
|
||||
(let [{:keys [x y width height]} position
|
||||
styles (js/getComputedStyle ^js node)
|
||||
get (fn [prop]
|
||||
|
@ -87,6 +88,7 @@
|
|||
:y (+ y height)
|
||||
:width width
|
||||
:height height
|
||||
:direction direction
|
||||
:font-family (str (get "font-family"))
|
||||
:font-size (str (get "font-size"))
|
||||
:font-weight (str (get "font-weight"))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue