britzl / defold-richtext

Defold-RichText is a system to create styled text based on an HTML inspired markup language
MIT License
75 stars 12 forks source link

The new 5.8.0 tag parser generates empty text words that can break layout #49

Closed dapetcu21 closed 5 years ago

dapetcu21 commented 5 years ago

Stuff like this happens:

Screenshot 2019-09-08 at 13 44 22

Printing out the generated words table, I notice there's some empty text nodes, including one at the very end, which creates the extra newline (see words[7] and words[8] in the output below):

The text and options fed to richtext.create():

DEBUG:SCRIPT: "We'll be bringing in a subject. They're a trained actor, but should be fully in character for the duration. I'm to be considered invisible and inaudible by the actor, but I'll be guiding you along.<nobr> <img=t:advance/></nobr>",
dialogue,
{ --[[0x136f546e0]]
  combine_words = true,
  align = hash: [ALIGN_CENTER],
  fonts = { --[[0x12070b0e0]]
    timer = { --[[0x12070bd80]]
      regular = hash: [timer]
    },
    title = { --[[0x12070bbd0]]
      bold_italic = hash: [title_bolditalic],
      regular = hash: [title],
      italic = hash: [title_italic],
      bold = hash: [title_bold]
    },
    dialogue_bold = { --[[0x12070b6e0]]
      bold_italic = hash: [dialogue_italic],
      regular = hash: [dialogue_bold],
      italic = hash: [dialogue_bolditalic],
      bold = hash: [dialogue]
    },
    dialogue = { --[[0x12070b130]]
      bold_italic = hash: [dialogue_bolditalic],
      regular = hash: [dialogue],
      italic = hash: [dialogue_italic],
      bold = hash: [dialogue_bold]
    },
    document_serif = { --[[0x12070b670]]
      bold_italic = hash: [document_serif_bolditalic],
      regular = hash: [document_serif],
      italic = hash: [document_serif_italic],
      bold = hash: [document_serif_bold]
    },
    document = { --[[0x12070b7a0]]
      regular = hash: [document],
      italic = hash: [document_italic],
      bold = hash: [document_bold]
    },
    dialogue_small = { --[[0x12070b370]]
      bold_italic = hash: [dialogue_bolditalic_small],
      regular = hash: [dialogue_small],
      italic = hash: [dialogue_italic_small],
      bold = hash: [dialogue_bold_small]
    },
    dialogue_italic = { --[[0x12070b5b0]]
      bold_italic = hash: [dialogue_bold],
      regular = hash: [dialogue_italic],
      italic = hash: [dialogue],
      bold = hash: [dialogue_bolditalic]
    }
  },
  layers = { --[[0x1207049c0]]
    fonts = { --[[0x12066cd40]]
      hash: [timer] = hash: [tutor_timer],
      hash: [title_bolditalic] = hash: [tutor_title_bolditalic],
      hash: [document_serif_italic] = hash: [tutor_document_serif_italic],
      hash: [title_bold] = hash: [tutor_title_bold],
      hash: [title_italic] = hash: [tutor_title_italic],
      hash: [dialogue_bold_small] = hash: [tutor_dialogue_bold_small],
      hash: [dialogue_bolditalic_small] = hash: [tutor_dialogue_bolditalic_small],
      hash: [dialogue_italic_small] = hash: [tutor_dialogue_italic_small],
      hash: [dialogue_small] = hash: [tutor_dialogue_small],
      hash: [dialogue_italic] = hash: [tutor_dialogue_italic],
      hash: [dialogue] = hash: [tutor_dialogue],
      hash: [dialogue_bolditalic] = hash: [tutor_dialogue_bolditalic],
      hash: [dialogue_bold] = hash: [tutor_dialogue_bold],
      hash: [document] = hash: [tutor_document],
      hash: [document_italic] = hash: [tutor_document_italic],
      hash: [document_bold] = hash: [tutor_document_bold],
      hash: [document_serif] = hash: [tutor_document_serif],
      hash: [document_serif_bold] = hash: [tutor_document_serif_bold],
      hash: [title] = hash: [tutor_title],
      hash: [document_serif_bolditalic] = hash: [tutor_document_serif_bolditalic]
    },
    spinescenes = { } --[[0x136d608f0]],
    images = { } --[[0x136d608a0]]
  },
  parent = @(398.80001831055, 137.89999389648, 0),
  width = 1255
}

And the words table:

DEBUG:SCRIPT: 
{ --[[0x136f54830]]
  1 = { --[[0x136f51100]]
    outline = vmath.vector4(0, 0, 0, 0),
    size = 1,
    color = vmath.vector4(1, 1, 1, 1),
    metrics = { --[[0x136e547b0]]
      width = 1156,
      max_descent = 13,
      max_ascent = 48,
      height = 61,
      total_width = 1167
    },
    text = "We'll be bringing in a subject. They're a trained ",
    tags = { } --[[0x136f555f0]],
    node = We'll be bringing in a subject. They're a trained @(-583.5, 0, 0),
    font = "dialogue",
    shadow = vmath.vector4(0, 0, 0, 0)
  },
  2 = { --[[0x136f38750]]
    outline = vmath.vector4(0, 0, 0, 0),
    size = 1,
    color = vmath.vector4(1, 1, 1, 1),
    metrics = { --[[0x136de9360]]
      width = 1093,
      max_descent = 13,
      max_ascent = 48,
      height = 61,
      total_width = 1104
    },
    text = "actor, but should be fully in character for the ",
    tags = { ... } --[[0x136f555f0]],
    node = actor, but should be fully in character for the @(-552, -61, 0),
    font = "dialogue",
    shadow = vmath.vector4(0, 0, 0, 0)
  },
  3 = { --[[0x136f39d60]]
    outline = vmath.vector4(0, 0, 0, 0),
    size = 1,
    color = vmath.vector4(1, 1, 1, 1),
    metrics = { --[[0x136da5680]]
      width = 1057,
      max_descent = 13,
      max_ascent = 48,
      height = 61,
      total_width = 1068
    },
    text = "duration. I'm to be considered invisible and ",
    tags = { ... } --[[0x136f555f0]],
    node = duration. I'm to be considered invisible and @(-534, -122, 0),
    font = "dialogue",
    shadow = vmath.vector4(0, 0, 0, 0)
  },
  4 = { --[[0x136f016b0]]
    outline = vmath.vector4(0, 0, 0, 0),
    size = 1,
    color = vmath.vector4(1, 1, 1, 1),
    metrics = { --[[0x136d28390]]
      width = 1248,
      max_descent = 13,
      max_ascent = 48,
      height = 61,
      total_width = 1248
    },
    text = "inaudible by the actor, but I'll be guiding you along.",
    tags = { ... } --[[0x136f555f0]],
    node = inaudible by the actor, but I'll be guiding you along.@(-654.5, -183, 0),
    font = "dialogue",
    shadow = vmath.vector4(0, 0, 0, 0)
  },
  5 = { --[[0x136ed7d60]]
    outline = vmath.vector4(0, 0, 0, 0),
    size = 1,
    color = vmath.vector4(1, 1, 1, 1),
    font = "dialogue",
    text = " ",
    nobr = true,
    node =  @(593.5, -183, 0),
    metrics = { --[[0x136d1c5c0]]
      width = 0,
      max_descent = 13,
      max_ascent = 48,
      height = 0,
      total_width = 11
    },
    tags = { --[[0x136ee3fa0]]
      nobr = true,
      img = "t:advance"
    },
    linebreak = false,
    tag = "nobr",
    shadow = vmath.vector4(0, 0, 0, 0)
  },
  6 = { --[[0x136ece3a0]]
    outline = vmath.vector4(0, 0, 0, 0),
    size = 1,
    color = vmath.vector4(1, 1, 1, 1),
    font = "dialogue",
    text = "",
    nobr = true,
    image = { --[[0x136eda4d0]]
      anim = "advance",
      texture = "t"
    },
    node = box@(604.5, -183, 0),
    tags = { --[[0x136ee3fa0]]
      nobr = true,
      img = "t:advance"
    },
    metrics = { --[[0x136d01700]]
      width = 50,
      height = 50,
      total_width = 50
    },
    tag = "img",
    shadow = vmath.vector4(0, 0, 0, 0)
  },
  7 = { --[[0x136ec67c0]]
    outline = vmath.vector4(0, 0, 0, 0),
    size = 1,
    color = vmath.vector4(1, 1, 1, 1),
    font = "dialogue",
    text = "",
    nobr = true,
    node = @(654.5, -183, 0),
    metrics = { --[[0x136d03b70]]
      width = 0,
      max_descent = 13,
      max_ascent = 48,
      height = 61,
      total_width = 0
    },
    tags = { --[[0x136ec5860]]
      nobr = true
    },
    linebreak = false,
    tag = "nobr",
    shadow = vmath.vector4(0, 0, 0, 0)
  },
  8 = { --[[0x136ebeab0]]
    outline = vmath.vector4(0, 0, 0, 0),
    size = 1,
    color = vmath.vector4(1, 1, 1, 1),
    font = "dialogue",
    text = "",
    node = @(0, -244, 0),
    tags = { } --[[0x136ec8680]],
    metrics = { --[[0x136d05070]]
      width = 0,
      max_descent = 13,
      max_as...
[Output truncated]
britzl commented 5 years ago

Fixed in 5.10.1