diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index b3e28446a..bbcda170f 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -18,6 +18,7 @@ Hope everyone is enjoying the holidays this week! - `class` shapes use monospaced font. [#521](https://github.com/terrastruct/d2/pull/521) - Sequence diagram edge group labels have more reasonable padding. [#512](https://github.com/terrastruct/d2/pull/512) - ELK layout engine preserves order of nodes. [#282](https://github.com/terrastruct/d2/issues/282) +- Non-markdown text (`shape: text` without language block) works with `bold`, `italic`, `underline`, and `font-size`. [#528](https://github.com/terrastruct/d2/pull/528) - Markdown headings set font-family explicitly, so that external stylesheets with more specific targeting don't override it. [#525](https://github.com/terrastruct/d2/pull/525) #### Bugfixes ⛑️ diff --git a/d2exporter/export.go b/d2exporter/export.go index 1eb2e6445..9706365f0 100644 --- a/d2exporter/export.go +++ b/d2exporter/export.go @@ -81,19 +81,17 @@ func applyStyles(shape *d2target.Shape, obj *d2graph.Object) { if obj.Attributes.Style.FontColor != nil { shape.Color = obj.Attributes.Style.FontColor.Value } - if obj.Attributes.Shape.Value != d2target.ShapeText { - if obj.Attributes.Style.Italic != nil { - shape.Italic, _ = strconv.ParseBool(obj.Attributes.Style.Italic.Value) - } - if obj.Attributes.Style.Bold != nil { - shape.Bold, _ = strconv.ParseBool(obj.Attributes.Style.Bold.Value) - } - if obj.Attributes.Style.Underline != nil { - shape.Underline, _ = strconv.ParseBool(obj.Attributes.Style.Underline.Value) - } - if obj.Attributes.Style.Font != nil { - shape.FontFamily = obj.Attributes.Style.Font.Value - } + if obj.Attributes.Style.Italic != nil { + shape.Italic, _ = strconv.ParseBool(obj.Attributes.Style.Italic.Value) + } + if obj.Attributes.Style.Bold != nil { + shape.Bold, _ = strconv.ParseBool(obj.Attributes.Style.Bold.Value) + } + if obj.Attributes.Style.Underline != nil { + shape.Underline, _ = strconv.ParseBool(obj.Attributes.Style.Underline.Value) + } + if obj.Attributes.Style.Font != nil { + shape.FontFamily = obj.Attributes.Style.Font.Value } } diff --git a/d2graph/d2graph.go b/d2graph/d2graph.go index ebaf0274c..da137cc12 100644 --- a/d2graph/d2graph.go +++ b/d2graph/d2graph.go @@ -441,7 +441,14 @@ func (obj *Object) AbsIDArray() []string { } func (obj *Object) Text() *d2target.MText { - isBold := !obj.IsContainer() + isBold := !obj.IsContainer() && obj.Attributes.Shape.Value != "text" + isItalic := false + if obj.Attributes.Style.Bold != nil && obj.Attributes.Style.Bold.Value == "true" { + isBold = true + } + if obj.Attributes.Style.Italic != nil && obj.Attributes.Style.Italic.Value == "true" { + isItalic = true + } fontSize := d2fonts.FONT_SIZE_M if obj.OuterSequenceDiagram() == nil { if obj.IsContainer() { @@ -464,7 +471,7 @@ func (obj *Object) Text() *d2target.MText { Text: obj.Attributes.Label.Value, FontSize: fontSize, IsBold: isBold, - IsItalic: false, + IsItalic: isItalic, Language: obj.Attributes.Language, Shape: obj.Attributes.Shape.Value, @@ -908,12 +915,14 @@ func (g *Graph) SetDimensions(mtexts []*d2target.MText, ruler *textmeasure.Ruler return err } dims = d2target.NewTextDimensions(width, height) - } else { + } else if obj.Attributes.Language != "" { var err error dims, err = getMarkdownDimensions(mtexts, ruler, obj.Text(), fontFamily) if err != nil { return err } + } else { + dims = getTextDimensions(mtexts, ruler, obj.Text(), fontFamily) } innerLabelPadding = 0 } else if obj.Attributes.Shape.Value == d2target.ShapeClass { diff --git a/d2renderers/d2sketch/testdata/twitter/sketch.exp.svg b/d2renderers/d2sketch/testdata/twitter/sketch.exp.svg index f93b93c1f..a45b29f99 100644 --- a/d2renderers/d2sketch/testdata/twitter/sketch.exp.svg +++ b/d2renderers/d2sketch/testdata/twitter/sketch.exp.svg @@ -796,7 +796,7 @@ width="3454" height="2449" viewBox="-100 -100 3454 2449">aabbllmm

nn

-
oocciikkdd

gg

-
hhjj

ee

-
ff1122 334455667788 - +aabbllmmnnoocciikkddgghhjjeeff1122 334455667788 + - + - + aabbllmm

nn

-
oocciikkdd

gg

-
hhjj

ee

-
ff1122 334455667788 - +aabbllmmnnoocciikkddgghhjjeeff1122 334455667788 + - + - - + + xy

The top of the mountain

-
JoeDonald

Cats, no less liquid than their shadows, offer no angles to the wind.

+xyThe top of the mountainJoeDonald

Cats, no less liquid than their shadows, offer no angles to the wind.

If we can't fix it, it ain't broke.

Dieters live life in the fasting lane.

-

i am top left

-

i am top right

-

i am bottom left

-

i am bottom right

-
- +
i am top lefti am top righti am bottom lefti am bottom right + xy

The top of the mountain

-
JoeDonald

Cats, no less liquid than their shadows, offer no angles to the wind.

+xyThe top of the mountainJoeDonald

Cats, no less liquid than their shadows, offer no angles to the wind.

If we can't fix it, it ain't broke.

Dieters live life in the fasting lane.

-

i am top left

-

i am top right

-

i am bottom left

-

i am bottom right

-
- +
i am top lefti am top righti am bottom lefti am bottom right + poll the peopleresultsunfavorablefavorablewill of the people

A winning strategy

-
+ poll the peopleresultsunfavorablefavorablewill of the people

A winning strategy

-
+ mixed togethersugarsolution we get +mixed togethersugarsolution we get mixed togethersugarsolution we get +mixed togethersugarsolution we get

Markdown: Syntax

-
ab +ab

Markdown: Syntax

-
ab +ab markdown

Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

-
+ markdown

Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

-
+ markdown

Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

-
+ markdown

Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

-
+

code

-
ab +ab

code

-
ab +ab bearmama bearpapa bear + + + \ No newline at end of file diff --git a/e2etests/testdata/stable/text_font_sizes/elk/board.exp.json b/e2etests/testdata/stable/text_font_sizes/elk/board.exp.json new file mode 100644 index 000000000..ae4e7c84e --- /dev/null +++ b/e2etests/testdata/stable/text_font_sizes/elk/board.exp.json @@ -0,0 +1,211 @@ +{ + "name": "", + "fontFamily": "SourceSansPro", + "shapes": [ + { + "id": "bear", + "type": "text", + "pos": { + "x": 64, + "y": 153 + }, + "width": 44, + "height": 28, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "transparent", + "stroke": "#0A0F25", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "bear", + "fontSize": 22, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 44, + "labelHeight": 28, + "zIndex": 0, + "level": 1 + }, + { + "id": "mama bear", + "type": "text", + "pos": { + "x": 12, + "y": 17 + }, + "width": 135, + "height": 36, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "transparent", + "stroke": "#0A0F25", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "mama bear", + "fontSize": 28, + "fontFamily": "DEFAULT", + "language": "", + "color": "#676C7E", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 135, + "labelHeight": 36, + "zIndex": 0, + "level": 1 + }, + { + "id": "papa bear", + "type": "text", + "pos": { + "x": 167, + "y": 12 + }, + "width": 134, + "height": 41, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "transparent", + "stroke": "#0A0F25", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "papa bear", + "fontSize": 32, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": false, + "underline": true, + "labelWidth": 134, + "labelHeight": 41, + "zIndex": 0, + "level": 1 + } + ], + "connections": [ + { + "id": "(mama bear -> bear)[0]", + "src": "mama bear", + "srcArrow": "none", + "srcLabel": "", + "dst": "bear", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "#0D32B2", + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#676C7E", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 79.5, + "y": 53 + }, + { + "x": 79.5, + "y": 153 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + }, + { + "id": "(papa bear -> bear)[0]", + "src": "papa bear", + "srcArrow": "none", + "srcLabel": "", + "dst": "bear", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "#0D32B2", + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#676C7E", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 234, + "y": 53 + }, + { + "x": 234, + "y": 103 + }, + { + "x": 94.16666666666666, + "y": 103 + }, + { + "x": 94.16666666666666, + "y": 153 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + } + ] +} diff --git a/e2etests/testdata/stable/text_font_sizes/elk/sketch.exp.svg b/e2etests/testdata/stable/text_font_sizes/elk/sketch.exp.svg new file mode 100644 index 000000000..506609593 --- /dev/null +++ b/e2etests/testdata/stable/text_font_sizes/elk/sketch.exp.svg @@ -0,0 +1,805 @@ + +bearmama bearpapa bear + + + \ No newline at end of file diff --git a/testdata/d2exporter/TestExport/shape/text_color.exp.json b/testdata/d2exporter/TestExport/shape/text_color.exp.json index 102ec04c2..426109644 100644 --- a/testdata/d2exporter/TestExport/shape/text_color.exp.json +++ b/testdata/d2exporter/TestExport/shape/text_color.exp.json @@ -34,7 +34,7 @@ "language": "markdown", "color": "red", "italic": false, - "bold": true, + "bold": false, "underline": false, "labelWidth": 0, "labelHeight": 0,