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

add font_load helper function

parent 7a4c160e
Loading
Loading
Loading
Loading
+3 −6
Original line number Diff line number Diff line
@@ -56,13 +56,10 @@ ReturnCode document_setup_defaults(Document* doc) {
        path_parts.end());
  }

  static const auto default_font_sans = "Arial,Helvetica:style=Regular,Roman";
  doc->font_sans.font_family_css = "Helvetica, Arial, sans-serif";
  if (!findFontSystem(default_font_sans, &doc->font_sans.font_file)) {
    return ReturnCode::errorf(
  if (!font_load(DefaultFont::HELVETICA_REGULAR, &doc->font_sans)) {
    return ReturnCode::error(
        "EARG",
        "unable to find default sans-sans font ($0)",
        default_font_sans);
        "unable to find default sans-sans font (Helvetica/Arial)");
  }

  return OK;
+33 −0
Original line number Diff line number Diff line
@@ -82,6 +82,39 @@ bool findFontSystem(
  return true;
}

ReturnCode font_load(DefaultFont font_name, FontInfo* font_info) {
  std::string font_css;
  std::string font_fc;

  switch (font_name) {
    default:
    case SANS_REGULAR:
    case HELVETICA_REGULAR:
      font_css = "Helvetica,'Helvetica Neue','Nimbus Sans L',Arial,sans-serif";
      font_fc = "Helvetica,Helvetica Neue,Nimbus Sans L,Arial:style=Regular,Roman";
      break;

    case SANS_MEDIUM:
    case HELVETICA_MEDIUM:
      font_css = "Helvetica,'Helvetica Neue','Nimbus Sans L',Arial,sans-serif";
      font_fc = "Helvetica,Helvetica Neue,Nimbus Sans L,Arial:style=Medium,Roman";
      break;

    case SANS_BOLD:
    case HELVETICA_BOLD:
      font_css = "Helvetica,'Helvetica Neue','Nimbus Sans L',Arial,sans-serif";
      font_fc = "Helvetica,Helvetica Neue,Nimbus Sans L,Arial:style=Bold,Roman";
      break;
  }

  font_info->font_family_css = font_css;

  if (!findFontSystem(font_fc, &font_info->font_file)) {
    return ERROR;
  }

  return OK;
}

} // namespace plotfx
+12 −1
Original line number Diff line number Diff line
@@ -39,8 +39,19 @@ bool findFontSimple(
    FontInfo* font_file);

bool findFontSystem(
    const std::string& font_pattenr,
    const std::string& font_pattern,
    std::string* font_file);

enum DefaultFont {
  SANS_REGULAR,
  SANS_MEDIUM,
  SANS_BOLD,
  HELVETICA_REGULAR,
  HELVETICA_MEDIUM,
  HELVETICA_BOLD,
};

ReturnCode font_load(DefaultFont font_name, FontInfo* font_info);

} // namespace plotfx