Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
alixander committed Nov 8, 2024
1 parent fe9a5e1 commit a8bf438
Showing 11 changed files with 4,123 additions and 615 deletions.
8 changes: 1 addition & 7 deletions d2exporter/export.go
Original file line number Diff line number Diff line change
@@ -144,6 +144,7 @@ func toShape(obj *d2graph.Object, g *d2graph.Graph) d2target.Shape {
shape.Pos = d2target.NewPoint(int(obj.TopLeft.X), int(obj.TopLeft.Y))
shape.Width = int(obj.Width)
shape.Height = int(obj.Height)
shape.Language = obj.Language

text := obj.Text()
shape.Bold = text.IsBold
@@ -165,9 +166,6 @@ func toShape(obj *d2graph.Object, g *d2graph.Graph) d2target.Shape {
applyStyles(shape, obj)

switch strings.ToLower(obj.Shape.Value) {
case d2target.ShapeCode, d2target.ShapeText:
shape.Language = obj.Language
shape.Label = obj.Label.Value
case d2target.ShapeClass:
shape.Class = *obj.Class
// The label is the header for classes and tables, which is set in client to be 4 px larger than the object's set font size
@@ -179,10 +177,6 @@ func toShape(obj *d2graph.Object, g *d2graph.Graph) d2target.Shape {
if obj.ContentAspectRatio != nil {
shape.ContentAspectRatio = go2.Pointer(*obj.ContentAspectRatio)
}
case d2target.ShapePage:
if obj.IsSequenceDiagramNote() {
shape.Language = obj.Language
}
}
shape.Label = text.Text
shape.LabelWidth = text.Dimensions.Width
13 changes: 5 additions & 8 deletions d2graph/d2graph.go
Original file line number Diff line number Diff line change
@@ -582,7 +582,8 @@ func (obj *Object) GetFill() string {

func (obj *Object) GetStroke(dashGapSize interface{}) string {
shape := obj.Shape.Value
if obj.Language != "" {
if strings.EqualFold(shape, d2target.ShapeCode) ||
strings.EqualFold(shape, d2target.ShapeText) {
return color.N1
}
if strings.EqualFold(shape, d2target.ShapeClass) ||
@@ -936,7 +937,9 @@ func (obj *Object) GetLabelSize(mtexts []*d2target.MText, ruler *textmeasure.Rul

var dims *d2target.TextDimensions
switch shapeType {
case d2target.ShapeText:
case d2target.ShapeClass:
dims = GetTextDimensions(mtexts, ruler, obj.Text(), go2.Pointer(d2fonts.SourceCodePro))
default:
if obj.Language == "latex" {
width, height, err := d2latex.Measure(obj.Text().Text)
if err != nil {
@@ -952,12 +955,6 @@ func (obj *Object) GetLabelSize(mtexts []*d2target.MText, ruler *textmeasure.Rul
} else {
dims = GetTextDimensions(mtexts, ruler, obj.Text(), fontFamily)
}

case d2target.ShapeClass:
dims = GetTextDimensions(mtexts, ruler, obj.Text(), go2.Pointer(d2fonts.SourceCodePro))

default:
dims = GetTextDimensions(mtexts, ruler, obj.Text(), fontFamily)
}

if shapeType == d2target.ShapeSQLTable && obj.Label.Value == "" {
Loading

0 comments on commit a8bf438

Please sign in to comment.