Commit 0396d164 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

graphics: add colour to TextStyle

parent 4c7880bc
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -145,7 +145,8 @@ Status Rasterizer::strokePath(
Status Rasterizer::drawTextGlyphs(
    const FontInfo& font_info,
    const GlyphPlacement* glyphs,
    size_t glyph_count) {
    size_t glyph_count,
    const TextStyle& style) {
  if (!ft_ready) {
    return ERROR;
  }
@@ -162,6 +163,13 @@ Status Rasterizer::drawTextGlyphs(
    return ERROR;
  }

  cairo_set_source_rgba(
     cr_ctx,
     style.colour.red(),
     style.colour.green(),
     style.colour.blue(),
     style.colour.alpha());

  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);
+2 −1
Original line number Diff line number Diff line
@@ -74,7 +74,8 @@ public:
  Status drawTextGlyphs(
      const FontInfo& font_info,
      const GlyphPlacement* glyphs,
      size_t glyph_count);
      size_t glyph_count,
      const TextStyle& style);

  MeasureTable measures;
  FT_Library ft;
+8 −7
Original line number Diff line number Diff line
@@ -44,11 +44,11 @@ Status drawText(
    const std::string& text,
    double x,
    double y,
    const TextStyle& text_style,
    const TextStyle& style,
    Layer* layer) {
  FontInfo font_info {
    .font_file = "/usr/share/fonts/google-roboto/Roboto-Medium.ttf",
    .font_size = text_style.font_size
    .font_size = style.font_size
  };

  std::vector<GlyphPlacement> glyphs;
@@ -57,9 +57,9 @@ Status drawText(
      x,
      y,
      font_info,
      text_style.direction,
      text_style.halign,
      text_style.valign,
      style.direction,
      style.halign,
      style.valign,
      &layer->text_shaper,
      [&glyphs] (const GlyphPlacement& g) { glyphs.emplace_back(g); });

@@ -67,15 +67,16 @@ Status drawText(
    return rc;
  }

  return drawTextGlyphs(font_info, glyphs.data(), glyphs.size(), layer);
  return drawTextGlyphs(font_info, glyphs.data(), glyphs.size(), style, layer);
}

Status drawTextGlyphs(
    const FontInfo& font_info,
    const GlyphPlacement* glyphs,
    size_t glyph_count,
    const TextStyle& style,
    Layer* layer) {
  return layer->rasterizer.drawTextGlyphs(font_info, glyphs, glyph_count);
  return layer->rasterizer.drawTextGlyphs(font_info, glyphs, glyph_count, style);
}

} // namespace plotfx
+3 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@
#pragma once
#include "plotfx.h"
#include "path.h"
#include "colour.h"

namespace plotfx {
class Layer;
@@ -52,6 +53,7 @@ struct TextStyle {
  TextHAlign halign;
  TextVAlign valign;
  double font_size;
  Colour colour;
};

struct FontInfo {
@@ -84,6 +86,7 @@ Status drawTextGlyphs(
    const FontInfo& font_info,
    const GlyphPlacement* glyphs,
    size_t glyph_count,
    const TextStyle& style,
    Layer* layer);