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

simplify the text layouting code

parent ea6047e9
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -48,7 +48,6 @@ struct Layer {
  double dpi;
  FontInfo font;
  Measure font_size;
  const std::shared_ptr<text::TextShaper> text_shaper;
  const std::function<Status (const layer_ops::Op&)> apply;
};

+1 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@
#include "measure.h"
#include "brush.h"
#include "text.h"
#include "text_layout.h"

namespace fviz {
namespace layer_ops {
+2 −6
Original line number Diff line number Diff line
@@ -24,8 +24,7 @@ ReturnCode layer_bind_img(
    const Color& background_color,
    std::function<Status (const unsigned char* data, size_t len)> submit,
    LayerRef* layer) {
  auto text_shaper = std::make_shared<text::TextShaper>();
  auto raster = std::make_shared<Rasterizer>(width, height, dpi, text_shaper);
  auto raster = std::make_shared<Rasterizer>(width, height, dpi);
  raster->clear(background_color);

  layer->reset(new Layer {
@@ -33,7 +32,6 @@ ReturnCode layer_bind_img(
    .height = height,
    .dpi = dpi,
    .font_size = font_size,
    .text_shaper = text_shaper,
    .apply = [submit, raster] (auto op) {
      return std::visit([submit, raster] (auto&& op) {
        using T = std::decay_t<decltype(op)>;
@@ -62,8 +60,7 @@ ReturnCode layer_bind_png(
    const Color& background_color,
    std::function<Status (const std::string&)> submit,
    LayerRef* layer) {
  auto text_shaper = std::make_shared<text::TextShaper>();
  auto raster = std::make_shared<Rasterizer>(width, height, dpi, text_shaper);
  auto raster = std::make_shared<Rasterizer>(width, height, dpi);
  raster->clear(background_color);

  layer->reset(new Layer {
@@ -71,7 +68,6 @@ ReturnCode layer_bind_png(
    .height = height,
    .dpi = dpi,
    .font_size = font_size,
    .text_shaper = text_shaper,
    .apply = [submit, raster] (auto op) {
      return std::visit([submit, raster] (auto&& op) {
        using T = std::decay_t<decltype(op)>;
+0 −1
Original line number Diff line number Diff line
@@ -262,7 +262,6 @@ ReturnCode layer_bind_svg(
    .height = svg->height = height,
    .dpi = dpi,
    .font_size = font_size,
    .text_shaper = std::make_shared<text::TextShaper>(),
    .apply = [dpi, svg, submit] (const auto& op) {
      return std::visit([dpi, svg, submit] (auto&& op) {
        using T = std::decay_t<decltype(op)>;
+2 −13
Original line number Diff line number Diff line
@@ -21,17 +21,10 @@ namespace fviz {
Rasterizer::Rasterizer(
    uint32_t width_,
    uint32_t height_,
    double dpi_,
    std::shared_ptr<text::TextShaper> text_shaper_) :
    double dpi_) :
    width(width_),
    height(height_),
    dpi(dpi_),
    text_shaper(text_shaper_),
    ft_ready(false) {
  if (!FT_Init_FreeType(&ft)) {
    ft_ready = true;
  }

    dpi(dpi_) {
  cr_surface = cairo_image_surface_create(
      CAIRO_FORMAT_ARGB32,
      width,
@@ -41,10 +34,6 @@ Rasterizer::Rasterizer(
}

Rasterizer::~Rasterizer() {
  if (ft_ready) {
    FT_Done_FreeType(ft);
  }

  cairo_destroy(cr_ctx);
  cairo_surface_destroy(cr_surface);
}
Loading