Commit 310d63c6 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

update the text layout api so that input text must be provided as a text span list

parent 56797825
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
@@ -29,15 +29,19 @@ Status drawTextLabel(
    double rotate,
    const TextStyle& style,
    Layer* layer) {
  text::TextSpan span;
  span.text = text;

  Rectangle bbox;
  std::vector<text::GlyphSpan> spans;
  std::vector<text::GlyphSpan> glyphs;
  auto rc = text::text_layout_hline(
      text,
      &span,
      &span + 1,
      style.direction,
      style.font,
      style.font_size,
      layer->dpi,
      &spans,
      &glyphs,
      &bbox);

  auto offset = layout_align(bbox, position, align_x, align_y);
@@ -46,8 +50,8 @@ Status drawTextLabel(
    return rc;
  }

  for (auto& span : spans) {
    for (auto& g : span.glyphs) {
  for (auto& gg : glyphs) {
    for (auto& g : gg.glyphs) {
      g.x += offset.x;
      g.y += offset.y;
    }
@@ -62,7 +66,7 @@ Status drawTextLabel(
  op.rotate = rotate;
  op.rotate_pivot = position;
  op.style = style;
  op.spans = std::move(spans);
  op.spans = std::move(glyphs);
  op.origin = offset;

  return layer->apply(op);
+4 −3
Original line number Diff line number Diff line
@@ -31,9 +31,10 @@ namespace fviz::text {
 * (spans) must be handled by a mechanism higher up in the stack.
 */
ReturnCode text_analyze_bidi_line(
    const std::string& text,
    TextDirection base_text_direction,
    TextLine* text_span);
    const TextSpan* text_begin,
    const TextSpan* text_end,
    TextDirection text_direction_base,
    TextLine* text_line);

} // namespace fviz::text
+12 −3
Original line number Diff line number Diff line
@@ -18,11 +18,12 @@
namespace fviz::text {

ReturnCode text_analyze_bidi_line(
    const std::string& text,
    TextDirection base_text_direction,
    const TextSpan* text_begin,
    const TextSpan* text_end,
    TextDirection text_direction_base,
    TextLine* text_line) {
  FriBidiParType fb_basedir;
  switch (base_text_direction) {
  switch (text_direction_base) {
    case TextDirection::LTR:
      fb_basedir = FRIBIDI_PAR_LTR;
      break;
@@ -31,6 +32,14 @@ ReturnCode text_analyze_bidi_line(
      break;
  }

  // combine all spans into a single string
  // TODO: ensure that each span ends up as it's own text run for font fallback
  // and shaping
  std::string text;
  for (auto text_iter = text_begin; text_iter != text_end; ++text_iter) {
    text += text_iter->text;
  }

  // convert to fribidi string
  std::vector<FriBidiChar> fb_str(text.size(), 0);
  auto fb_str_len = fribidi_charset_to_unicode(
+10 −5
Original line number Diff line number Diff line
@@ -132,19 +132,20 @@ Status text_layout_hline(
}

Status text_layout_hline(
    const std::string& text_logical,
    const TextDirection base_text_direction,
    const TextSpan* text_begin,
    const TextSpan* text_end,
    const TextDirection text_direction_base,
    const FontInfo& font_info,
    double font_size,
    double dpi,
    std::vector<GlyphSpan>* glyph_spans,
    Rectangle* bbox) {
  TextLine text_line;
  text_analyze_bidi_line(text_logical, base_text_direction, &text_line);
  text_analyze_bidi_line(text_begin, text_end, text_direction_base, &text_line);

  return text_layout_hline(
      text_line,
      base_text_direction,
      text_direction_base,
      font_info,
      font_size,
      dpi,
@@ -158,8 +159,12 @@ Status text_measure_span(
    double font_size,
    double dpi,
    Rectangle* bbox) {
  TextSpan span;
  span.text = text;

  return text_layout_hline(
      text,
      &span,
      &span + 1,
      TextDirection::LTR,
      font_info,
      font_size,
+3 −2
Original line number Diff line number Diff line
@@ -109,8 +109,9 @@ Status text_layout_hline(
 * controls the base writing direction of the line
 */
Status text_layout_hline(
    const std::string& text_logical,
    TextDirection base_direction,
    const TextSpan* text_begin,
    const TextSpan* text_end,
    TextDirection text_direction_base,
    const FontInfo& font,
    double font_size,
    double dpi,