Commit 47c7812b authored by Paul Asmuth's avatar Paul Asmuth
Browse files

consistent usage of FontInfo struct

parent 515833d6
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@
#include "utils/return_code.h"
#include "graphics/measure.h"
#include "graphics/colour.h"
#include "graphics/text.h"
#include "element.h"

namespace plotfx {
@@ -44,9 +45,9 @@ struct Document {
  Colour background_colour;
  Colour text_colour;
  Colour border_colour;
  std::string font_serif;
  std::string font_sans;
  std::string font_mono;
  FontInfo font_serif;
  FontInfo font_sans;
  FontInfo font_mono;
  std::vector<std::string> font_searchpath;
  std::vector<ElementRef> roots;
};
+4 −2
Original line number Diff line number Diff line
@@ -36,11 +36,13 @@ namespace plotfx {
bool findFontSimple(
    const std::string& font_name,
    const std::vector<std::string>& search_paths,
    std::string* font_file) {
    FontInfo* font) {
  for (const auto& p : search_paths) {
    auto candidate = FileUtil::joinPaths(p, font_name + ".ttf");
    if (FileUtil::exists(candidate)) {
      *font_file = candidate;
      *font = FontInfo {
        .font_file = candidate
      };
      return true;
    }
  }
+2 −1
Original line number Diff line number Diff line
@@ -29,13 +29,14 @@
 */
#pragma once
#include "plotfx.h"
#include "text.h"

namespace plotfx {

bool findFontSimple(
    const std::string& font_name,
    const std::vector<std::string>& search_paths,
    std::string* font_file);
    FontInfo* font_file);

} // namespace plotfx
+3 −5
Original line number Diff line number Diff line
@@ -143,7 +143,6 @@ Status Rasterizer::strokePath(
}

Status Rasterizer::drawTextGlyphs(
    const FontInfo& font_info,
    const GlyphPlacement* glyphs,
    size_t glyph_count,
    const TextStyle& style) {
@@ -153,12 +152,12 @@ Status Rasterizer::drawTextGlyphs(

  // FIXME cache
  FT_Face ft_font;
  if (FT_New_Face(ft, font_info.font_file.c_str(), 0, &ft_font)) {
  if (FT_New_Face(ft, style.font.font_file.c_str(), 0, &ft_font)) {
    return ERROR;
  }

  auto dpi = measures.dpi;
  if (FT_Set_Char_Size(ft_font, 0, font_info.font_size * 64, dpi, dpi)) {
  if (FT_Set_Char_Size(ft_font, 0, style.font_size * 64, dpi, dpi)) {
    FT_Done_Face(ft_font);
    return ERROR;
  }
@@ -172,14 +171,13 @@ Status Rasterizer::drawTextGlyphs(

  auto cairo_face = cairo_ft_font_face_create_for_ft_face(ft_font, 0);
  cairo_set_font_face(cr_ctx, cairo_face);
  cairo_set_font_size(cr_ctx, (font_info.font_size / 72.0) * dpi);
  cairo_set_font_size(cr_ctx, (style.font_size / 72.0) * dpi);

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


    cairo_glyphs[i].index = g.codepoint;
    cairo_glyphs[i].x = g.x;
    cairo_glyphs[i].y = g.y;
+0 −1
Original line number Diff line number Diff line
@@ -72,7 +72,6 @@ public:
      const StrokeStyle& style);

  Status drawTextGlyphs(
      const FontInfo& font_info,
      const GlyphPlacement* glyphs,
      size_t glyph_count,
      const TextStyle& style);
Loading