Commit 667ec5b2 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

move the font information into the text span struct

parent a0e34af5
Loading
Loading
Loading
Loading
+23 −2
Original line number Diff line number Diff line
@@ -41,8 +41,6 @@ Status drawTextLabel(
      text_begin,
      text_end,
      style.direction,
      style.font,
      style.font_size,
      layer->dpi,
      &glyphs,
      &bbox);
@@ -85,6 +83,8 @@ Status drawTextLabel(
    Layer* layer) {
  text::TextSpan span;
  span.text = text;
  span.font = style.font;
  span.font_size = style.font_size;
  return drawTextLabel(&span, &span + 1, position, align_x, align_y, 0, style, layer);
}

@@ -98,5 +98,26 @@ Status drawTextLabel(
  return drawTextLabel(text, position, align_x, align_y, 0, style, layer);
}

Status text_measure_label(
    const std::string& text,
    TextDirection text_direction_base,
    const FontInfo& font,
    double font_size,
    double dpi,
    Rectangle* bbox) {
  text::TextSpan span;
  span.text = text;
  span.font = font;
  span.font_size = font_size;

  return text_layout_line(
      &span,
      &span + 1,
      text_direction_base,
      dpi,
      nullptr,
      bbox);
}

} // namespace fviz
+12 −0
Original line number Diff line number Diff line
@@ -64,5 +64,17 @@ Status drawTextLabel(
    const TextStyle& text_style,
    Layer* layer);

/**
 * Convenience function to measure the size of a simple piece of text.
 */
Status text_measure_label(
    const std::string& text,
    TextDirection text_direction_base,
    const FontInfo& font,
    double font_size,
    double dpi,
    Rectangle* bbox);


} // namespace fviz
+10 −44
Original line number Diff line number Diff line
@@ -46,12 +46,7 @@ struct TextLine {
};

Status text_place_hrun(
    const std::string& text_logical,
    const TextDirection text_direction,
    const std::string& text_language,
    const std::string& text_script,
    const FontInfo& font_info,
    double font_size,
    const TextSpan& span,
    double dpi,
    std::vector<GlyphPlacement>* glyphs,
    double* span_length,
@@ -59,12 +54,12 @@ Status text_place_hrun(
    double* span_bottom) {
  std::vector<GlyphInfo> glyph_list;
  auto shaping_rc = text_shape_run_with_font_fallback(
      text_logical,
      text_direction,
      text_language,
      text_script,
      font_info,
      font_size,
      span.text,
      span.text_direction,
      span.language,
      span.script,
      span.font,
      span.font_size,
      dpi,
      &glyph_list);

@@ -90,8 +85,6 @@ Status text_place_hrun(

Status text_place_hline(
    const TextLine& text_line,
    const FontInfo& font_info,
    double font_size,
    double dpi,
    std::vector<GlyphPlacementGroup>* glyphs,
    Rectangle* bbox) {
@@ -102,12 +95,7 @@ Status text_place_hline(
    double span_length = 0.0;
    std::vector<GlyphPlacement> span_glyphs;
    auto rc = text_place_hrun(
        text_line.spans[i].text,
        text_line.spans[i].text_direction,
        text_line.spans[i].language,
        text_line.spans[i].script,
        font_info,
        font_size,
        text_line.spans[i],
        dpi,
        &span_glyphs,
        &span_length,
@@ -218,8 +206,6 @@ Status text_layout_line(
    const TextSpan* text_begin,
    const TextSpan* text_end,
    const TextDirection text_direction_base,
    const FontInfo& font_info,
    double font_size,
    double dpi,
    std::vector<GlyphPlacementGroup>* glyphs,
    Rectangle* bbox) {
@@ -253,8 +239,6 @@ Status text_layout_line(
  // place the text glyphs on the screen
  return text_place_hline(
      text_line,
      font_info,
      font_size,
      dpi,
      glyphs,
      bbox);
@@ -270,36 +254,18 @@ Status text_layout_line(
    Rectangle* bbox) {
  TextSpan span;
  span.text = text;
  span.font = font_info;
  span.font_size = font_size;

  return text_layout_line(
      &span,
      &span + 1,
      text_direction_base,
      font_info,
      font_size,
      dpi,
      glyphs,
      bbox);
}

Status text_measure_line(
    const std::string& text,
    TextDirection text_direction_base,
    const FontInfo& font,
    double font_size,
    double dpi,
    Rectangle* bbox) {
  return text_layout_line(
      text,
      text_direction_base,
      font,
      font_size,
      dpi,
      nullptr,
      bbox);
}


} // namespace text
} // namespace fviz
+2 −14
Original line number Diff line number Diff line
@@ -38,6 +38,8 @@ struct TextSpan {
  TextDirection text_direction;
  std::string language;
  std::string script;
  FontInfo font;
  double font_size;
};


@@ -74,8 +76,6 @@ Status text_layout_line(
    const TextSpan* text_begin,
    const TextSpan* text_end,
    TextDirection text_direction_base,
    const FontInfo& font,
    double font_size,
    double dpi,
    std::vector<GlyphPlacementGroup>* glyphs,
    Rectangle* bbox);
@@ -99,17 +99,5 @@ Status text_layout_line(
    Rectangle* bbox);


/**
 * Measure the size of a single line of text.
 */
Status text_measure_line(
    const std::string& text,
    TextDirection text_direction_base,
    const FontInfo& font,
    double font_size,
    double dpi,
    Rectangle* bbox);


} // namespace fviz::text
+1 −1
Original line number Diff line number Diff line
@@ -83,7 +83,7 @@ ReturnCode layout(
  style.font_size = config->label_font_size;

  Rectangle label_bbox;
  if (auto rc = text::text_measure_line(
  if (auto rc = text_measure_label(
        config->label,
        TextDirection::LTR,
        config->label_font,
Loading