FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Warn on FreeType missing glyphs. by anntzer · Pull Request #12759 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cpp  (2) .py  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
10 changes: 8 additions & 2 deletions lib/matplotlib/backends/backend_pdf.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import sys
import time
import types
import warnings
import zlib

import numpy as np
Expand Down Expand Up @@ -937,8 +938,13 @@ def get_char_width(charcode):
s, flags=LOAD_NO_SCALE | LOAD_NO_HINTING).horiAdvance
return cvt(width)

widths = [get_char_width(charcode)
for charcode in range(firstchar, lastchar+1)]
with warnings.catch_warnings():
# Ignore 'Required glyph missing from current font' warning
# from ft2font: here we're just builting the widths table, but
# the missing glyphs may not even be used in the actual string.
warnings.filterwarnings("ignore")
widths = [get_char_width(charcode)
for charcode in range(firstchar, lastchar+1)]
descriptor['MaxWidth'] = max(widths)

# Make the "Differences" array, sort the ccodes < 255 from
Expand Down
23 changes: 20 additions & 3 deletions src/ft2font.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "ft2font.h"
#include "mplutils.h"
#include "py_exceptions.h"

#ifndef M_PI
#define M_PI 3.14159265358979323846264338328
Expand Down Expand Up @@ -162,9 +163,24 @@ FT2Image::draw_rect_filled(unsigned long x0, unsigned long y0, unsigned long x1,

inline double conv(long v)
{
return double(v) / 64.0;
return v / 64.;
}

static FT_UInt ft_get_char_index_or_warn(FT_Face face, FT_ULong charcode)
{
FT_UInt glyph_index = FT_Get_Char_Index(face, charcode);
if (!glyph_index) {
PyErr_WarnFormat(NULL, 1, "Glyph %lu missing from current font.", charcode);
// Apparently PyErr_WarnFormat returns 0 even if the exception propagates
// due to running with -Werror, so check the error flag directly instead.
if (PyErr_Occurred()) {
throw py::exception();
}
}
return glyph_index;
}


int FT2Font::get_path_count()
{
// get the glyph as a path, a list of (COMMAND, *args) as described in matplotlib.path
Expand Down Expand Up @@ -610,7 +626,7 @@ void FT2Font::set_text(
FT_BBox glyph_bbox;
FT_Pos last_advance;

glyph_index = FT_Get_Char_Index(face, codepoints[n]);
glyph_index = ft_get_char_index_or_warn(face, codepoints[n]);

// retrieve kerning distance and move pen position
if (use_kerning && previous && glyph_index) {
Expand Down Expand Up @@ -663,7 +679,8 @@ void FT2Font::set_text(

void FT2Font::load_char(long charcode, FT_Int32 flags)
{
int error = FT_Load_Char(face, (unsigned long)charcode, flags);
FT_UInt glyph_index = ft_get_char_index_or_warn(face, (FT_ULong)charcode);
int error = FT_Load_Glyph(face, glyph_index, flags);

if (error) {
throw std::runtime_error("Could not load charcode");
Expand Down
4 changes: 2 additions & 2 deletions src/ft2font_wrapper.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -998,8 +998,8 @@ static PyObject *PyFT2Font_get_char_index(PyFT2Font *self, PyObject *args, PyObj
const char *PyFT2Font_get_sfnt__doc__ =
"get_sfnt(name)\n"
"\n"
"Get all values from the SFNT names table. Result is a dictionary whose"
"key is the platform-ID, ISO-encoding-scheme, language-code, and"
"Get all values from the SFNT names table. Result is a dictionary whose "
"key is the platform-ID, ISO-encoding-scheme, language-code, and "
"description.\n";

static PyObject *PyFT2Font_get_sfnt(PyFT2Font *self, PyObject *args, PyObject *kwds)
Expand Down

Back | FazBrowse Home | New Git URL