mirror of
https://github.com/penpot/penpot.git
synced 2026-11-06 01:50:39 +00:00
Render Japanese annotations in HTML and SVG and expose their styles in CSS code generation. Preserve vertical position data from WASM, while keeping the legacy SVG renderer on its horizontal layout path. Cover generated markup, styles and copied SVG output.
56 lines
2.0 KiB
Clojure
56 lines
2.0 KiB
Clojure
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
;;
|
|
;; Copyright (c) KALEIDOS SUBSIDIARY SL
|
|
|
|
(ns app.util.text.writing-mode
|
|
"Writing mode of text content as the active renderer lays it out. Only the
|
|
WASM renderer supports vertical writing; the SVG renderer lays every text
|
|
out horizontally and leaves the stored attrs as they are."
|
|
(:require
|
|
[app.common.types.shape :as cts]
|
|
[app.common.types.text :as txt]
|
|
[app.common.types.text.cjk-layout :as cjk]))
|
|
|
|
(defn vertical-layout-active?
|
|
"True when the active renderer lays out vertical writing (WASM)."
|
|
[]
|
|
cts/wasm-enabled?)
|
|
|
|
(defn content-writing-mode
|
|
"Effective writing mode of a text content (see `cjk/content-writing-mode`)."
|
|
[content]
|
|
(when ^boolean (vertical-layout-active?)
|
|
(cjk/content-writing-mode content)))
|
|
|
|
(defn vertical-text-content?
|
|
"True when the text content flows vertically under the active renderer."
|
|
[content]
|
|
(and ^boolean (vertical-layout-active?)
|
|
(cjk/vertical-text-content? content)))
|
|
|
|
(defn stale-vertical-layout?
|
|
"True when the content is stored as vertical but the active renderer lays
|
|
it out horizontally, so a WASM-computed layout (such as `:position-data`)
|
|
does not match."
|
|
[content]
|
|
(and (not ^boolean (vertical-layout-active?))
|
|
(cjk/vertical-text-content? content)))
|
|
|
|
(defn renderable-paragraph
|
|
"Paragraph attrs as the active renderer lays them out: without the vertical
|
|
writing attrs when the renderer lays every text out horizontally."
|
|
[paragraph]
|
|
(if ^boolean (vertical-layout-active?)
|
|
paragraph
|
|
(apply dissoc paragraph cjk/whole-shape-paragraph-attrs)))
|
|
|
|
(defn renderable-content
|
|
"Text content as the active renderer lays it out (see
|
|
`renderable-paragraph`)."
|
|
[content]
|
|
(if ^boolean (vertical-layout-active?)
|
|
content
|
|
(txt/transform-nodes txt/is-paragraph-node? renderable-paragraph content)))
|