Commit ce95f3b7 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

return a list of 'GlyphSpans' so that we can assign per-glyph fonts

parent b3998725
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -61,6 +61,10 @@ ReturnCode font_load(const std::string& font_file, FontRef* font_ref) {
  return OK;
}

void* font_get_freetype(FontRef font) {
  return font->ft_font;
}

ReturnCode font_get_glyph_path(
    FontRef font,
    double font_size,
+2 −0
Original line number Diff line number Diff line
@@ -49,6 +49,8 @@ ReturnCode font_get_glyph_path(
    uint32_t codepoint,
    Path* path);

void* font_get_freetype(FontRef font);

ReturnCode font_find(DefaultFont font_name, FontInfo* font_info);

ReturnCode font_find_expr(const Expr* expr, FontInfo* font_info);
+1 −1
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ struct BrushFillOp {

struct TextSpanOp {
  std::string text;
  std::vector<text::GlyphPlacement> glyphs;
  std::vector<text::GlyphSpan> spans;
  Point origin;
  double rotate;
  Point rotate_pivot;
+25 −23
Original line number Diff line number Diff line
@@ -180,11 +180,12 @@ Status svg_text_span_embed(
    SVGDataRef svg) {
  const auto& style = op.style;

  for (const auto& g : op.glyphs) {
  for (const auto& s : op.spans) {
    for (const auto& g : s.glyphs) {
      Path gp;

      auto rc = font_get_glyph_path(
        op.style.font.font,
          s.font.font,
          op.style.font_size,
          dpi,
          g.codepoint,
@@ -205,6 +206,7 @@ Status svg_text_span_embed(
          << "/>"
          << "\n";
    }
  }

  return OK;
}
+46 −53
Original line number Diff line number Diff line
@@ -129,15 +129,8 @@ Status Rasterizer::strokePath(const layer_ops::BrushStrokeOp& op) {
}

Status Rasterizer::drawText(const layer_ops::TextSpanOp& op) {
  if (!ft_ready) {
    return ERROR;
  }

  // FIXME cache
  FT_Face ft_font;
  if (FT_New_Face(ft, op.style.font.font_file.c_str(), 0, &ft_font)) {
    return ERROR;
  }
  for (const auto& span : op.spans) {
    auto ft_font = static_cast<FT_Face>(font_get_freetype(span.font.font));

    auto font_size_ft = op.style.font_size * (72.0 / dpi) * 64;
    if (FT_Set_Char_Size(ft_font, 0, font_size_ft, dpi, dpi)) {
@@ -156,10 +149,10 @@ Status Rasterizer::drawText(const layer_ops::TextSpanOp& op) {
    cairo_set_font_face(cr_ctx, cairo_face);
    cairo_set_font_size(cr_ctx, op.style.font_size);

  auto glyph_count = op.glyphs.size();
    auto glyph_count = span.glyphs.size();
    auto cairo_glyphs = cairo_glyph_allocate(glyph_count);
    for (int i = 0; i < glyph_count; ++i) {
    const auto& g = op.glyphs[i];
      const auto& g = span.glyphs[i];
      //FT_Load_Glyph(ft_font, g.codepoint, FT_LOAD_DEFAULT);

      cairo_glyphs[i].index = g.codepoint;
@@ -185,8 +178,8 @@ Status Rasterizer::drawText(const layer_ops::TextSpanOp& op) {
    cairo_show_glyphs(cr_ctx, cairo_glyphs, glyph_count);
    cairo_glyph_free(cairo_glyphs);
    cairo_font_face_destroy(cairo_face);
  }

  FT_Done_Face(ft_font);
  return OK;
}

Loading