terrastruct / d2

D2 is a modern diagram scripting language that turns text to diagrams.
https://d2lang.com
Mozilla Public License 2.0
17.14k stars 422 forks source link

more font optimization: subset by style #1107

Open alixander opened 1 year ago

alixander commented 1 year ago

currently we subset fonts by collecting all characters and encoding, in every style, those characters.

we can further optimize by subsetting each character WITH its style, so that the font encoding for bold only includes the bolded characters, the font encoding for italic only includes the italics, etc.

related initial optimization: https://github.com/terrastruct/d2/pull/1089

alixander commented 1 year ago

@donglixiaoche can you leave a comment here so i can assign you? (github won't let me assign otherwise)

donglixiaoche commented 1 year ago

@alixander coooopy, wanna give this issue a shot

donglixiaoche commented 1 year ago

@alixander when will a text be semibold? there's no such a flag inside Text struct indicates it's semibold, only bold flag

type Text struct {
    Label      string `json:"label"`
    FontSize   int    `json:"fontSize"`
    FontFamily string `json:"fontFamily"`
    Language   string `json:"language"`
    Color      string `json:"color"`

    Italic    bool `json:"italic"`
    Bold      bool `json:"bold"`
    Underline bool `json:"underline"`

    LabelWidth  int    `json:"labelWidth"`
    LabelHeight int    `json:"labelHeight"`
    LabelFill   string `json:"labelFill,omitempty"`
}
donglixiaoche commented 1 year ago

ohh i see, when there is markdown inside diagram, right? when will there be a markdown ? an explanation?

donglixiaoche commented 1 year ago

https://github.com/terrastruct/d2/blob/feae388f19b72bb9c90de7452472bfd154bcd86c/d2renderers/d2svg/d2svg.go#L1373-L1394

and why do we need regular font for md class? below these lines, we also add semibold font for md class