Commit 2fcbf615 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

simplify the text shaper interface

parent 2ef464ba
Loading
Loading
Loading
Loading
+23 −22
Original line number Diff line number Diff line
@@ -26,16 +26,22 @@ Status text_layout_ltr(
    const TextShaper* shaper,
    std::vector<GlyphPlacement>* glyphs,
    Rectangle* bbox) {
  double line_length = 0.0f;
  double top = 0.0f;
  double bottom = 0.0f;

  std::vector<GlyphInfo> glyphs_raw;
  auto rc = shaper->shapeText(
      text,
      font_info,
      font_size,
      dpi,
      [&] (const GlyphInfo& gi) {
      &glyphs_raw);

  if (rc != OK) {
    return rc;
  }

  double line_length = 0.0f;
  double line_top = 0.0f;
  double line_bottom = 0.0f;
  for (const auto& gi : glyphs_raw) {
    GlyphPlacement gp = {
      .codepoint = gi.codepoint,
      .x = line_length,
@@ -47,24 +53,19 @@ Status text_layout_ltr(
    }

    line_length += gi.advance_x;
        top = std::min(-gi.metrics_ascender, top);
        bottom = std::max(-gi.metrics_descender, bottom);
      });

  if (rc != OK) {
    return rc;
    line_top = std::min(-gi.metrics_ascender, line_top);
    line_bottom = std::max(-gi.metrics_descender, line_bottom);
  }

  *bbox = Rectangle(
      0,
      top,
      line_top,
      line_length,
      bottom - top);
      line_bottom - line_top);

  return OK;
}


Status text_layout(
    const std::string& text,
    const FontInfo& font,
+2 −2
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ Status TextShaper::shapeText(
    const FontInfo& font,
    double font_size,
    double dpi,
    std::function<void (const GlyphInfo&)> glyph_cb) const {
    std::vector<GlyphInfo>* glyphs) const {
  if (!ft_ready) {
    if (FT_Init_FreeType(&ft)) {
      return ERROR;
@@ -72,7 +72,7 @@ Status TextShaper::shapeText(
    g.advance_y = glyph_positions[i].y_advance / 64.0;
    g.metrics_ascender = ft_font->size->metrics.ascender / 64.0; // FIXME this is constant for all glyphs
    g.metrics_descender = ft_font->size->metrics.descender / 64.0; // FIXME this is constant for all glyphs
    glyph_cb(g);
    glyphs->emplace_back(g);
  }

  hb_font_destroy(hb_font);
+1 −1
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ public:
      const FontInfo& font,
      double font_size,
      double dpi,
      std::function<void (const GlyphInfo&)> glyph_cb) const;
      std::vector<GlyphInfo>* glyphs) const;

protected:
  double dpi;