-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A dirty solution to #891 #960
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
53703a1
Close #891: a dirty solution to embedded bitmap fonts.
jackyyf 182c092
Testcase added.
jackyyf 12632ee
Change bitmap test suite.
jackyyf 013a73d
Remove unused StringIO.
jackyyf 36a8aba
Make bitmap test runnable as a standalone.
jackyyf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from helper import unittest, PillowTestCase | ||
from PIL import Image, ImageFont, ImageDraw | ||
|
||
class TestImageFontBitmap(PillowTestCase): | ||
def test_similar(self): | ||
text = 'EmbeddedBitmap' | ||
font_outline = ImageFont.truetype(font='Tests/fonts/DejaVuSans.ttf', size=24) | ||
font_bitmap = ImageFont.truetype(font='Tests/fonts/DejaVuSans-bitmap.ttf', size=24) | ||
size_outline, size_bitmap = font_outline.getsize(text), font_bitmap.getsize(text) | ||
size_final = max(size_outline[0], size_bitmap[0]), max(size_outline[1], size_bitmap[1]) | ||
im_bitmap = Image.new('RGB', size_final, (255, 255, 255)) | ||
im_outline = im_bitmap.copy() | ||
draw_bitmap, draw_outline = ImageDraw.Draw(im_bitmap), ImageDraw.Draw(im_outline) | ||
# Don't know why, but bitmap version is always vertical 1 pixel longer than outline one on my PC. | ||
# Revert back to both 0, 0 | ||
draw_bitmap.text((0, 0), text, fill=(0, 0, 0), font=font_bitmap) | ||
draw_outline.text((0, 0), text, fill=(0, 0, 0), font=font_outline) | ||
self.assert_image_similar(im_bitmap, im_outline, 0.01) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains 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 |
---|---|---|
|
@@ -18,6 +18,17 @@ | |
* Copyright (c) 1998-2007 by Secret Labs AB | ||
*/ | ||
|
||
/* | ||
* Notes: | ||
* Currently, embedded bitmap fonts within truetype fonts do not work | ||
* properly (see issue #891), truetype fonts are loaded with | ||
* FT_LOAD_NO_BITMAP load flags, resulting in embedded bitmap fonts | ||
* not being used. | ||
* | ||
* Yifu Yu<[email protected]> | ||
* 2014-10-15 | ||
*/ | ||
|
||
#include "Python.h" | ||
#include "Imaging.h" | ||
|
||
|
@@ -243,7 +254,7 @@ font_getsize(FontObject* self, PyObject* args) | |
&delta); | ||
x += delta.x; | ||
} | ||
error = FT_Load_Glyph(face, index, FT_LOAD_DEFAULT); | ||
error = FT_Load_Glyph(face, index, FT_LOAD_DEFAULT|FT_LOAD_NO_BITMAP); | ||
if (error) | ||
return geterror(error); | ||
if (i == 0) | ||
|
@@ -316,7 +327,7 @@ font_getabc(FontObject* self, PyObject* args) | |
int index, error; | ||
face = self->face; | ||
index = FT_Get_Char_Index(face, ch); | ||
error = FT_Load_Glyph(face, index, FT_LOAD_DEFAULT); | ||
error = FT_Load_Glyph(face, index, FT_LOAD_DEFAULT|FT_LOAD_NO_BITMAP); | ||
if (error) | ||
return geterror(error); | ||
a = face->glyph->metrics.horiBearingX / 64.0; | ||
|
@@ -364,7 +375,7 @@ font_render(FontObject* self, PyObject* args) | |
|
||
im = (Imaging) id; | ||
|
||
load_flags = FT_LOAD_RENDER; | ||
load_flags = FT_LOAD_RENDER|FT_LOAD_NO_BITMAP; | ||
if (mask) | ||
load_flags |= FT_LOAD_TARGET_MONO; | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add this at the bottom so the script is runnable as a standalone:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we still need it? I thought that this legacy code, because tests are run via
nosetests Tests/test_imagefont_bitmap.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@homm Travis CI runs the tests using
nosetests
, but at least I find it useful when debugging just a single test locally (or creating/adding new tests). Sure, there's anose
command to run a single test, but it's much easier and transparent to be able to dopython Tests/test_etc.py
, and it's only an extra couple of lines.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the contrary, it is much easier to run single tests with nose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. When I said single test I meant a single file, and
python Tests/test_etc.py
is the standard way to run a Python script, and a useful basic, extra option to having to remember a nose command and its syntax, especially for new contributors who may never have seen nosetests before.