Commit 5d0f1023 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

search for fonts in PLOTFX_FONT_PATH

parent e5d0a33d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ add_library(plotfxlib STATIC
    common/graphics/text_shaper.cc
    common/graphics/rasterize.cc
    common/graphics/png.cc
    common/graphics/font_lookup.cc
    common/element_factory.cc
    common/document.cc
    common/utils/random.cc
+19 −3
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@
#include "element_factory.h"
#include "graphics/layer.h"
#include "graphics/layout.h"
#include "graphics/font_lookup.h"
#include "common/config_helpers.h"

namespace plotfx {
@@ -44,9 +45,24 @@ Document::Document() :
    border_colour(Colour::fromRGB(.45,.45,.45)) {}

ReturnCode setupDocumentDefaults(Document* doc) {
  doc->font_serif = "/usr/share/fonts/google-roboto/Roboto-Medium.ttf";
  doc->font_sans = "/usr/share/fonts/google-roboto/Roboto-Medium.ttf";
  doc->font_mono = "/usr/share/fonts/google-roboto/Roboto-Medium.ttf";
  if (auto path = getenv("PLOTFX_FONT_PATH"); path) {
    auto path_parts = StringUtil::split(path, ":");
    doc->font_searchpath.insert(
        doc->font_searchpath.end(),
        path_parts.begin(),
        path_parts.end());
  }


  static const auto default_font_sans = "Roboto-Medium";
  if (!findFontSimple(default_font_sans, doc->font_searchpath, &doc->font_sans)) {
    return ReturnCode::errorf(
        "EARG",
        "unable to find default sans-sans font ($0); searched in: $1",
        default_font_sans,
        StringUtil::join(doc->font_searchpath, ", "));
  }

  return OK;
}

+1 −0
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ struct Document {
  std::string font_serif;
  std::string font_sans;
  std::string font_mono;
  std::vector<std::string> font_searchpath;
  std::vector<ElementRef> roots;
};

+2 −0
Original line number Diff line number Diff line
@@ -7,6 +7,8 @@ print_error () {
  printf "\033[0m\n"
}

export PLOTFX_FONT_PATH="$(pwd)/extra/fonts"

binfile="$1"
specfile="$2"
outfile="$3"