Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9983c66

Browse filesBrowse files
committed
Implement another approach
1 parent adebae4 commit 9983c66
Copy full SHA for 9983c66

File tree

Expand file treeCollapse file tree

5 files changed

+45
-29
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+45
-29
lines changed

‎lib/matplotlib/_text_helpers.py

Copy file name to clipboardExpand all lines: lib/matplotlib/_text_helpers.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,12 @@ def layout(string, font, *, kern_mode=KERNING_DEFAULT):
6060
print("Inside _text_helpers.py")
6161
# breakpoint()
6262
for char in string:
63+
print("\nchecking:", char, "\n")
6364
glyph_idx = font.get_char_index(ord(char))
6465
kern = (font.get_kerning(prev_glyph_idx, glyph_idx, kern_mode) / 64
6566
if prev_glyph_idx is not None else 0.)
6667
x += kern
67-
glyph = font.load_glyph(glyph_idx, flags=LOAD_NO_HINTING, fallback=True)
68+
glyph = font.load_glyph(glyph_idx, flags=LOAD_NO_HINTING)
6869
yield LayoutItem(char, glyph_idx, x, kern)
6970
x += glyph.linearHoriAdvance / 65536
7071
prev_glyph_idx = glyph_idx

‎lib/matplotlib/backends/backend_agg.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_agg.py
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
185185
return None
186186
# We pass '0' for angle here, since it will be rotated (in raster
187187
# space) in the following call to draw_text_image).
188-
print("BEFORE")
189188
font.set_text(s, 0, flags=flags)
190189
font.draw_glyphs_to_bitmap(
191190
antialiased=mpl.rcParams['text.antialiased'])

‎lib/matplotlib/backends/backend_pdf.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_pdf.py
+21-17Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,7 @@ def fontName(self, fontprop):
879879
_log.debug('Assigning font %s = %r', Fx, fname)
880880
Fxs.append(Fx)
881881

882+
# return only the first for Op.selectfont to work
882883
return Fxs[0]
883884

884885
def dviFontName(self, dvifont):
@@ -912,8 +913,7 @@ def dviFontName(self, dvifont):
912913
return pdfname
913914

914915
def writeFonts(self):
915-
# print("OHNO")
916-
# breakpoint()
916+
print("fonts: ", self.fontNames)
917917
fonts = {}
918918
for dviname, info in sorted(self.dviFontInfo.items()):
919919
Fx = info.pdfname
@@ -929,13 +929,6 @@ def writeFonts(self):
929929
else:
930930
# a normal TrueType font
931931
_log.debug('Writing TrueType font.')
932-
# characters = []
933-
print("lalalla")
934-
# breakpoint()
935-
# for key, val in self._char_to_font:
936-
# if val.fname == filename:
937-
# print("nice", filename)
938-
# characters.append(key)
939932
chars = self._character_tracker.used.get(filename)
940933
print("chars:", chars, " for font:", filename)
941934
if chars:
@@ -1079,14 +1072,14 @@ def createType1Descriptor(self, t1font, fontfile):
10791072
return fontdescObject
10801073

10811074
def _get_xobject_symbol_name(self, filename, symbol_name):
1075+
# since filename is a string
10821076
Fx = self.fontName(filename)
1083-
# TODO: XObject symbol name should be multiple names?
1084-
# list(map(lambda x: x.name.decode(), Fxs))
1085-
# Fx = Fxs[0]
1086-
return "-".join([
1077+
x = "-".join([
10871078
Fx.name.decode(),
10881079
os.path.splitext(os.path.basename(filename))[0],
10891080
symbol_name])
1081+
print("\n\nXOBJECT", x, "\n\n")
1082+
return x
10901083

10911084
_identityToUnicodeCMap = b"""/CIDInit /ProcSet findresource begin
10921085
12 dict begin
@@ -1113,6 +1106,7 @@ def embedTTF(self, filename, characters):
11131106
"""Embed the TTF font from the named file into the document."""
11141107

11151108
font = get_font(filename)
1109+
print("embedding:", font.fname)
11161110
fonttype = mpl.rcParams['pdf.fonttype']
11171111

11181112
def cvt(length, upe=font.units_per_EM, nearest=True):
@@ -1159,9 +1153,8 @@ def embedTTFType3(font, characters, descriptor):
11591153
def get_char_width(charcode):
11601154
s = ord(cp1252.decoding_table[charcode])
11611155
width = font.load_char(
1162-
s, fallback=False, flags=LOAD_NO_SCALE | LOAD_NO_HINTING).horiAdvance
1156+
s, flags=LOAD_NO_SCALE | LOAD_NO_HINTING).horiAdvance
11631157
return cvt(width)
1164-
11651158
with warnings.catch_warnings():
11661159
# Ignore 'Required glyph missing from current font' warning
11671160
# from ft2font: here we're just building the widths table, but
@@ -2424,6 +2417,11 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
24242417
-math.sin(a), math.cos(a),
24252418
x, y, Op.concat_matrix)
24262419
# Emit all the 1-byte characters in a BT/ET group.
2420+
2421+
x = self.file.fontName(prop)
2422+
print(x)
2423+
# breakpoint()
2424+
24272425
self.file.output(Op.begin_text,
24282426
self.file.fontName(prop), fontsize, Op.selectfont)
24292427
prev_start_x = 0
@@ -2439,12 +2437,18 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
24392437
prev_start_x = start_x
24402438
self.file.output(Op.end_text)
24412439
# Then emit all the multibyte characters, one at a time.
2440+
glyph_to_font = font.get_glyph_to_font()
24422441
for start_x, glyph_idx in multibyte_glyphs:
2443-
self._draw_xobject_glyph(font, fontsize, glyph_idx, start_x, 0)
2442+
self._draw_xobject_glyph(glyph_to_font, fontsize, glyph_idx, start_x, 0)
24442443
self.file.output(Op.grestore)
2444+
# print("fine here")
24452445

2446-
def _draw_xobject_glyph(self, font, fontsize, glyph_idx, x, y):
2446+
def _draw_xobject_glyph(self, glyph_to_font, fontsize, glyph_idx, x, y):
24472447
"""Draw a multibyte character from a Type 3 font as an XObject."""
2448+
if glyph_idx not in glyph_to_font:
2449+
# ideally raise.
2450+
pass
2451+
font = glyph_to_font[glyph_idx]
24482452
symbol_name = font.get_glyph_name(glyph_idx)
24492453
name = self.file._get_xobject_symbol_name(font.fname, symbol_name)
24502454
self.file.output(

‎src/ft2font.cpp

Copy file name to clipboardExpand all lines: src/ft2font.cpp
+14-6Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ FT2Font::~FT2Font()
375375
}
376376

377377
if (face) {
378+
printf("Deleting face from: %lu\n", face->num_glyphs);
378379
FT_Done_Face(face);
379380
}
380381
}
@@ -555,11 +556,11 @@ void FT2Font::set_text(
555556
if (bbox.xMin > bbox.xMax) {
556557
bbox.xMin = bbox.yMin = bbox.xMax = bbox.yMax = 0;
557558
}
558-
printf("\nMap: \n");
559-
// print out num_glyphs for the final FT2Font so its easy to track
560-
for (std::pair<const FT_UInt, FT2Font *> &x: glyph_to_font) {
561-
printf("%u: %lu \n", x.first, x.second->get_face()->num_glyphs);
562-
}
559+
// printf("\nMap: \n");
560+
// // print out num_glyphs for the final FT2Font so its easy to track
561+
// for (std::pair<const FT_UInt, FT2Font *> &x: glyph_to_font) {
562+
// printf("%u: %lu \n", x.first, x.second->get_face()->num_glyphs);
563+
// }
563564
}
564565

565566
void FT2Font::fill_glyphs(
@@ -685,6 +686,7 @@ bool FT2Font::load_char_with_fallback(FT2Font *&ft_object_with_glyph,
685686
bool override = false)
686687
{
687688
FT_UInt glyph_index = FT_Get_Char_Index(face, charcode);
689+
// printf("fallback glyph id: %u\n", glyph_index);
688690

689691
if (glyph_index || override) {
690692
charcode_error = FT_Load_Glyph(face, glyph_index, flags);
@@ -736,7 +738,8 @@ void FT2Font::load_glyph(FT_UInt glyph_index,
736738
void FT2Font::load_glyph(FT_UInt glyph_index, FT_Int32 flags)
737739
{
738740
// search cache first
739-
if (fallback == 1 && glyph_to_font.find(glyph_index) != glyph_to_font.end()) {
741+
if (fallback && glyph_to_font.find(glyph_index) != glyph_to_font.end()) {
742+
// printf("load_glyph: Already present in cache.\n");
740743
ft_object = glyph_to_font[glyph_index];
741744
return;
742745
}
@@ -778,6 +781,11 @@ void FT2Font::get_cbox(FT_BBox &bbox)
778781
FT_Glyph_Get_CBox(glyphs.back(), ft_glyph_bbox_subpixels, &bbox);
779782
}
780783

784+
void FT2Font::get_cbox(FT_BBox &bbox)
785+
{
786+
FT_Glyph_Get_CBox(glyphs.back(), ft_glyph_bbox_subpixels, &bbox);
787+
}
788+
781789
void FT2Font::get_width_height(long *width, long *height)
782790
{
783791
*width = advance;

‎src/ft2font_wrapper.cpp

Copy file name to clipboardExpand all lines: src/ft2font_wrapper.cpp
+8-4Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -766,8 +766,7 @@ static PyObject *PyFT2Font_load_char(PyFT2Font *self, PyObject *args, PyObject *
766766
long charcode;
767767
int fallback = 1;
768768
FT_Int32 flags = FT_LOAD_FORCE_AUTOHINT;
769-
const char *names[] = { "charcode", "flags", "fallback", NULL };
770-
printf("Loading char!\n");
769+
const char *names[] = { "charcode", "flags", NULL };
771770

772771
/* This makes a technically incorrect assumption that FT_Int32 is
773772
int. In theory it can also be long, if the size of int is less
@@ -776,9 +775,9 @@ static PyObject *PyFT2Font_load_char(PyFT2Font *self, PyObject *args, PyObject *
776775
&flags)) {
777776
return NULL;
778777
}
779-
778+
780779
FT2Font *ft_object = NULL;
781-
CALL_CPP("load_char", (self->x->load_char(charcode, flags, fallback, ft_object)));
780+
CALL_CPP("load_char", (self->x->load_char(charcode, flags, ft_object, (bool)fallback)));
782781
printf("Char %ld loaded to: %lu\n", charcode, ft_object->get_face()->num_glyphs);
783782

784783
FT2Font *ft_object = NULL;
@@ -819,6 +818,11 @@ static PyObject *PyFT2Font_load_glyph(PyFT2Font *self, PyObject *args, PyObject
819818
return NULL;
820819
}
821820

821+
// if (!PyArg_ParseTupleAndKeywords(
822+
// args, kwds, "I|i$p:load_glyph", (char **)names, &glyph_index, &flags, &fallback)) {
823+
// return NULL;
824+
// }
825+
822826
FT2Font *ft_object = NULL;
823827
CALL_CPP("load_glyph", (self->x->load_glyph(glyph_index, flags, ft_object, (bool)fallback)));
824828

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.