🐛 Fix not picking up font style / variant in new renderer

This commit is contained in:
Belén Albeza
2025-07-07 18:08:53 +02:00
parent a242962113
commit 098fd9fb0f
5 changed files with 30 additions and 5 deletions

View File

@@ -13,6 +13,7 @@
### :bug: Bugs fixed ### :bug: Bugs fixed
- Fix problem with booleans selection [Taiga #11627](https://tree.taiga.io/project/penpot/issue/11627) - Fix problem with booleans selection [Taiga #11627](https://tree.taiga.io/project/penpot/issue/11627)
- Fix missing font when copy&paste a chunk of text [Taiga #11522](https://tree.taiga.io/project/penpot/issue/11522)
## 2.9.0 (Unreleased) ## 2.9.0 (Unreleased)

View File

@@ -39,8 +39,8 @@
{:id "300italic" :name "300 (italic)" :weight "300" :style "italic" :suffix "lightitalic" :ttf-url "sourcesanspro-lightitalic.ttf"} {:id "300italic" :name "300 (italic)" :weight "300" :style "italic" :suffix "lightitalic" :ttf-url "sourcesanspro-lightitalic.ttf"}
{:id "regular" :name "regular" :weight "400" :style "normal" :ttf-url "sourcesanspro-regular.ttf"} {:id "regular" :name "regular" :weight "400" :style "normal" :ttf-url "sourcesanspro-regular.ttf"}
{:id "italic" :name "italic" :weight "400" :style "italic" :ttf-url "sourcesanspro-italic.ttf"} {:id "italic" :name "italic" :weight "400" :style "italic" :ttf-url "sourcesanspro-italic.ttf"}
{:id "bold" :name "bold" :weight "bold" :style "normal" :ttf-url "sourcesanspro-bold.ttf"} {:id "bold" :name "bold" :weight "700" :style "normal" :ttf-url "sourcesanspro-bold.ttf"}
{:id "bolditalic" :name "bold (italic)" :weight "bold" :style "italic" :ttf-url "sourcesanspro-bolditalic.ttf"} {:id "bolditalic" :name "bold (italic)" :weight "700" :style "italic" :ttf-url "sourcesanspro-bolditalic.ttf"}
{:id "black" :name "black" :weight "900" :style "normal" :ttf-url "sourcesanspro-black.ttf"} {:id "black" :name "black" :weight "900" :style "normal" :ttf-url "sourcesanspro-black.ttf"}
{:id "blackitalic" :name "black (italic)" :weight "900" :style "italic" :ttf-url "sourcesanspro-blackitalic.ttf"}]}]) {:id "blackitalic" :name "black (italic)" :weight "900" :style "italic" :ttf-url "sourcesanspro-blackitalic.ttf"}]}])

View File

@@ -169,7 +169,31 @@
(defn serialize-font-weight (defn serialize-font-weight
[font-weight] [font-weight]
(js/Number font-weight)) (if (number? font-weight)
font-weight
(let [font-weight-str (str font-weight)]
(cond
(re-matches #"\d+" font-weight-str)
(js/Number font-weight-str)
(str/includes? font-weight-str "bold")
700
(str/includes? font-weight-str "black")
900
(str/includes? font-weight-str "extrabold")
800
(str/includes? font-weight-str "extralight")
200
(str/includes? font-weight-str "light")
300
(str/includes? font-weight-str "medium")
500
(str/includes? font-weight-str "semibold")
600
(str/includes? font-weight-str "thin")
100
:else
400))))
(defn store-font (defn store-font
[shape-id font] [shape-id font]
@@ -182,6 +206,7 @@
weight (serialize-font-weight raw-weight) weight (serialize-font-weight raw-weight)
style (serialize-font-style (cond style (serialize-font-style (cond
(str/includes? font-variant-id "italic") "italic" (str/includes? font-variant-id "italic") "italic"
(str/includes? raw-weight "italic") "italic"
:else "normal")) :else "normal"))
asset-id (font-id->asset-id font-id font-variant-id) asset-id (font-id->asset-id font-id font-variant-id)
font-data {:wasm-id wasm-id font-data {:wasm-id wasm-id
@@ -189,6 +214,7 @@
:font-variant-id font-variant-id :font-variant-id font-variant-id
:style style :style style
:weight weight}] :weight weight}]
(store-font-id shape-id font-data asset-id emoji? fallback?))) (store-font-id shape-id font-data asset-id emoji? fallback?)))
(defn store-fonts (defn store-fonts

View File

@@ -520,7 +520,6 @@ export function createRootFromHTML(html, style) {
const fragment = mapContentFragmentFromHTML(html, style); const fragment = mapContentFragmentFromHTML(html, style);
const root = createRoot([], style); const root = createRoot([], style);
root.replaceChildren(fragment); root.replaceChildren(fragment);
console.log("ROOT", root);
return root; return root;
} }

View File

@@ -34,7 +34,6 @@ export function createRandomId() {
* @returns {HTMLElement} * @returns {HTMLElement}
*/ */
export function createElement(tag, options) { export function createElement(tag, options) {
console.log("createElement", options);
const element = document.createElement(tag); const element = document.createElement(tag);
if (options?.attributes) { if (options?.attributes) {
Object.entries(options.attributes).forEach(([name, value]) => Object.entries(options.attributes).forEach(([name, value]) =>