| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -192,9 +192,13 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath): | |||
| 192 | 192 | ||
| 193 | 193 | font = self._get_agg_font(prop) | |
| 194 | 194 | if font is None: return None | |
| 195 | - font.set_text(s, angle) | ||
| 195 | + if len(s)==1 and ord(s)>127: | ||
| 196 | + | ||
| 197 | + font.load_char(ord(s)) | ||
| 198 | + else: | ||
| 199 | + font.set_text(s, angle) | ||
| 196 | 200 | font.draw_glyphs_to_bitmap() | |
| 197 | - | ||
| 201 | + | ||
| 198 | 202 | self._renderer.draw_text(font, int(x), int(y), gc) | |
| 199 | 203 | ||
| 200 | 204 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -107,6 +107,16 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False): | |||
| 107 | 107 | """ | |
| 108 | 108 | Render the matplotlib.text.Text instance at x, y in window | |
| 109 | 109 | coords using GraphicsContext gc | |
| 110 | + | ||
| 111 | + **backend implementers note** When you are trying to determine | ||
| 112 | + if you have gotten your bounding box right (which is what | ||
| 113 | + enables the text layout/alignment to work properly), it helps to change the line in text.py | ||
| 114 | + | ||
| 115 | + if 0: bbox_artist(self, renderer) | ||
| 116 | + | ||
| 117 | + to if 1, and then the actual bounding box will be blotted | ||
| 118 | + along with your text. | ||
| 119 | + | ||
| 110 | 120 | """ | |
| 111 | 121 | pass | |
| 112 | 122 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -548,6 +548,7 @@ def __init__(self, | |||
| 548 | 548 | weight = None, | |
| 549 | 549 | stretch= None, | |
| 550 | 550 | size = None, | |
| 551 | + fname = None, # if this is set, it's a hardcoded filename to use | ||
| 551 | 552 | ): | |
| 552 | 553 | ||
| 553 | 554 | ||
@@ -567,12 +568,13 @@ def __init__(self, | |||
| 567 | 568 | self.__stretch = stretch | |
| 568 | 569 | self.__size = size | |
| 569 | 570 | self.__parent_size = fontManager.get_default_size() | |
| 570 | - | ||
| 571 | + self.fname = fname | ||
| 572 | + | ||
| 571 | 573 | def __hash__(self): | |
| 572 | 574 | return hash( ( | |
| 573 | 575 | tuple(self.__family), self.__style, self.__variant, | |
| 574 | 576 | self.__weight, self.__stretch, self.__size, | |
| 575 | - self.__parent_size)) | ||
| 577 | + self.__parent_size, self.fname)) | ||
| 576 | 578 | ||
| 577 | 579 | def __str__(self): | |
| 578 | 580 | return str((self.__family, self.__style, self.__variant, | |
@@ -844,7 +846,11 @@ def findfont(self, prop, fontext='ttf'): | |||
| 844 | 846 | Delete this file to have matplotlib rebuild the cache.""" | |
| 845 | 847 | ||
| 846 | 848 | debug = False | |
| 847 | - | ||
| 849 | + if prop.fname is not None: | ||
| 850 | + fname = prop.fname | ||
| 851 | + verbose.report('findfont returning %s'%fname, 'debug') | ||
| 852 | + return fname | ||
| 853 | + | ||
| 848 | 854 | if fontext == 'ttf': | |
| 849 | 855 | fontdict = self.ttfdict | |
| 850 | 856 | elif fontext == 'afm': | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -98,15 +98,15 @@ def draw(self, renderer): | |||
| 98 | 98 | Rectangle.draw(self, renderer) | |
| 99 | 99 | ||
| 100 | 100 | # position the text | |
| 101 | - self._set_text_position() | ||
| 101 | + self._set_text_position(renderer) | ||
| 102 | 102 | self._text.draw(renderer) | |
| 103 | 103 | ||
| 104 | - def _set_text_position(self): | ||
| 104 | + def _set_text_position(self, renderer): | ||
| 105 | 105 | """ Set text up so it draws in the right place. | |
| 106 | 106 | ||
| 107 | 107 | Currently support 'left', 'center' and 'right' | |
| 108 | 108 | """ | |
| 109 | - bbox = self.get_window_extent() | ||
| 109 | + bbox = self.get_window_extent(renderer) | ||
| 110 | 110 | l, b, w, h = bbox.get_bounds() | |
| 111 | 111 | ||
| 112 | 112 | # draw in center vertically | |
@@ -138,6 +138,9 @@ def get_required_width(self, renderer): | |||
| 138 | 138 | return w * (1.0 + (2.0 * self.PAD)) | |
| 139 | 139 | ||
| 140 | 140 | ||
| 141 | + def set_text_props(self, **kwargs): | ||
| 142 | + 'update the text properties with kwargs' | ||
| 143 | + self._text.update_properties(kwargs) | ||
| 141 | 144 | ||
| 142 | 145 | class Table(Artist): | |
| 143 | 146 | """ | |
@@ -239,7 +242,7 @@ def get_child_artists(self): | |||
| 239 | 242 | ||
| 240 | 243 | return self._cells.values() | |
| 241 | 244 | ||
| 242 | - def get_window_extent(self, renderer=None): | ||
| 245 | + def get_window_extent(self, renderer): | ||
| 243 | 246 | ||
| 244 | 247 | boxes = [c.get_window_extent(renderer) for c in self._cells] | |
| 245 | 248 | return bbox_all(boxes) | |
@@ -396,3 +399,7 @@ def _update_positions(self, renderer): | |||
| 396 | 399 | self._offset(ox, oy) | |
| 397 | 400 | ||
| 398 | 401 | ||
| 402 | + def get_celld(self): | ||
| 403 | + 'return a dict of cells in the table' | ||
| 404 | + return self._cells | ||
| 405 | + | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -52,10 +52,7 @@ def __init__(self, | |||
| 52 | 52 | self._text = text | |
| 53 | 53 | self._verticalalignment = verticalalignment | |
| 54 | 54 | self._horizontalalignment = horizontalalignment | |
| 55 | - self._multialignment = multialignment | ||
| 56 | - | ||
| 57 | - | ||
| 58 | - | ||
| 55 | + self._multialignment = multialignment | ||
| 59 | 56 | self._rotation = rotation | |
| 60 | 57 | self._fontproperties = fontproperties | |
| 61 | 58 | ||
@@ -469,6 +466,7 @@ def update_properties(self, d): | |||
| 469 | 466 | ||
| 470 | 467 | def is_math_text(self): | |
| 471 | 468 | if not matplotlib._havemath: return False | |
| 469 | + if len(self._text)<2: return False | ||
| 472 | 470 | return ( self._text.startswith('$') and | |
| 473 | 471 | self._text.endswith('$') ) | |
| 474 | 472 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -263,7 +263,7 @@ FT2Font::clear(const Py::Tuple & args) { | |||
| 263 | 263 | image.height = 0; | |
| 264 | 264 | image.offsetx = 0; | |
| 265 | 265 | image.offsety = 0; | |
| 266 | - | ||
| 266 | + | ||
| 267 | 267 | text = ""; | |
| 268 | 268 | angle = 0.0; | |
| 269 | 269 | ||
@@ -277,12 +277,16 @@ FT2Font::clear(const Py::Tuple & args) { | |||
| 277 | 277 | for (size_t i=0; i<gms.size(); i++) { | |
| 278 | 278 | Py_DECREF(gms[i]); | |
| 279 | 279 | } | |
| 280 | + | ||
| 280 | 281 | glyphs.resize(0); | |
| 281 | 282 | gms.resize(0); | |
| 282 | 283 | ||
| 283 | 284 | return Py::Object(); | |
| 284 | 285 | } | |
| 285 | 286 | ||
| 287 | + | ||
| 288 | + | ||
| 289 | + | ||
| 286 | 290 | char FT2Font::set_size__doc__[] = | |
| 287 | 291 | "set_size(ptsize, dpi)\n" | |
| 288 | 292 | "\n" | |
@@ -516,6 +520,7 @@ FT2Font::draw_bitmap( FT_Bitmap* bitmap, | |||
| 516 | 520 | if ( i >= width || j >= height ) | |
| 517 | 521 | continue; | |
| 518 | 522 | image.buffer[i + j*width] |= bitmap->buffer[q*bitmap->width + p]; | |
| 523 | + | ||
| 519 | 524 | } | |
| 520 | 525 | } | |
| 521 | 526 | } | |
@@ -614,9 +619,10 @@ char FT2Font::draw_glyphs_to_bitmap__doc__[] = | |||
| 614 | 619 | ; | |
| 615 | 620 | Py::Object | |
| 616 | 621 | FT2Font::draw_glyphs_to_bitmap(const Py::Tuple & args) { | |
| 622 | + | ||
| 617 | 623 | _VERBOSE("FT2Font::draw_glyphs_to_bitmap"); | |
| 618 | 624 | args.verify_length(0); | |
| 619 | - | ||
| 625 | + | ||
| 620 | 626 | FT_BBox string_bbox = compute_string_bbox(); | |
| 621 | 627 | ||
| 622 | 628 | image.width = (string_bbox.xMax-string_bbox.xMin) / 64+2; | |
@@ -627,17 +633,19 @@ FT2Font::draw_glyphs_to_bitmap(const Py::Tuple & args) { | |||
| 627 | 633 | image.offsety = -image.height; | |
| 628 | 634 | else | |
| 629 | 635 | image.offsety = (int)(-string_bbox.yMax/64.0); | |
| 630 | - | ||
| 636 | + | ||
| 637 | + | ||
| 631 | 638 | size_t numBytes = image.width*image.height; | |
| 632 | 639 | delete [] image.buffer; | |
| 633 | 640 | image.buffer = new unsigned char [numBytes]; | |
| 634 | 641 | for (size_t n=0; n<numBytes; n++) | |
| 635 | 642 | image.buffer[n] = 0; | |
| 643 | + | ||
| 644 | + | ||
| 636 | 645 | ||
| 637 | 646 | for ( size_t n = 0; n < glyphs.size(); n++ ) | |
| 638 | 647 | { | |
| 639 | 648 | FT_BBox bbox; | |
| 640 | - | ||
| 641 | 649 | FT_Glyph_Get_CBox(glyphs[n], ft_glyph_bbox_pixels, &bbox); | |
| 642 | 650 | ||
| 643 | 651 | error = FT_Glyph_To_Bitmap(&glyphs[n], | |
@@ -648,17 +656,20 @@ FT2Font::draw_glyphs_to_bitmap(const Py::Tuple & args) { | |||
| 648 | 656 | ); | |
| 649 | 657 | if (error) | |
| 650 | 658 | throw Py::RuntimeError("Could not convert glyph to bitmap"); | |
| 651 | - | ||
| 659 | + | ||
| 652 | 660 | FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyphs[n]; | |
| 653 | - /* now, draw to our target surface (convert position) */ | ||
| 661 | + // now, draw to our target surface (convert position) | ||
| 654 | 662 | ||
| 655 | 663 | //bitmap left and top in pixel, string bbox in subpixel | |
| 656 | - | ||
| 657 | - draw_bitmap( &bitmap->bitmap, | ||
| 658 | - bitmap->left-string_bbox.xMin/64, | ||
| 659 | - string_bbox.yMax/64-bitmap->top+1 | ||
| 660 | - ); | ||
| 664 | + FT_Int x = (FT_Int)(bitmap->left-string_bbox.xMin/64.); | ||
| 665 | + FT_Int y = (FT_Int)(string_bbox.yMax/64.-bitmap->top+1); | ||
| 666 | + //make sure the index is non-neg | ||
| 667 | + x = x<0?0:x; | ||
| 668 | + y = y<0?0:y; | ||
| 669 | + | ||
| 670 | + draw_bitmap( &bitmap->bitmap, x, y); | ||
| 661 | 671 | } | |
| 672 | + | ||
| 662 | 673 | return Py::Object(); | |
| 663 | 674 | } | |
| 664 | 675 | ||
@@ -744,8 +755,7 @@ FT2Font::get_charmap(const Py::Tuple & args) { | |||
| 744 | 755 | Py::Dict charmap; | |
| 745 | 756 | ||
| 746 | 757 | FT_ULong code = FT_Get_First_Char(face, &index); | |
| 747 | - while (code != 0) { | ||
| 748 | - //charmap[Py::Long((long) code)] = Py::Int((int) index); | ||
| 758 | + while (index != 0) { | ||
| 749 | 759 | charmap[Py::Int((int) index)] = Py::Long((long) code); | |
| 750 | 760 | code = FT_Get_Next_Char(face, code, &index); | |
| 751 | 761 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments