Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more font optimization: subset by style #1107

Open
alixander opened this issue Mar 29, 2023 · 5 comments
Open

more font optimization: subset by style #1107

alixander opened this issue Mar 29, 2023 · 5 comments
Assignees

Comments

@alixander
Copy link
Collaborator

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: #1089

@alixander
Copy link
Collaborator Author

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

@ShupingHe
Copy link
Contributor

@alixander coooopy, wanna give this issue a shot

@ShupingHe
Copy link
Contributor

ShupingHe commented Apr 20, 2023

@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"`
}

@ShupingHe
Copy link
Contributor

ShupingHe commented Apr 20, 2023

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

@ShupingHe
Copy link
Contributor

ShupingHe commented Apr 20, 2023

d2/d2renderers/d2svg/d2svg.go

Lines 1373 to 1394 in feae388

appendOnTrigger(
buf,
source,
[]string{
`class="text"`,
`class="text `,
`class="md"`,
},
fmt.Sprintf(`
.%s .text {
font-family: "%s-font-regular";
}
@font-face {
font-family: %s-font-regular;
src: url("%s");
}`,
diagramHash,
diagramHash,
diagramHash,
fontFamily.Font(0, d2fonts.FONT_STYLE_REGULAR).GetEncodedSubset(corpus),
),
)

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

2 participants