-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d12c01
commit 935a7f2
Showing
8 changed files
with
147 additions
and
41 deletions.
There are no files selected for viewing
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
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
File renamed without changes.
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,79 @@ | ||
import pangocffi | ||
from pangocffi import Layout, TabArray, TabAlign | ||
from tests.context_creator import ContextCreator | ||
import locale | ||
|
||
|
||
def test_tab_array_decimal_places(): | ||
""" | ||
In this test, we're aligning a list of labels and numbers. | ||
The list of numbers is deliberately ugly, as ideally all numbers would be | ||
given the same number of decimal places. But this test confirms that the | ||
numbers are aligned at the comma. | ||
""" | ||
|
||
width = 100 | ||
height = 100 | ||
# CFFIs and Contexts | ||
context_creator = ContextCreator.create_pdf( | ||
'tests/acceptance/output/tab-array-decimal-places.pdf', width, height | ||
) | ||
pangocairo = context_creator.pangocairo | ||
cairo_context = context_creator.cairo_context | ||
|
||
lines = [ | ||
['Berlin', 891.3], | ||
['Hamburg', 755.2], | ||
['München', 310.7], | ||
['Stuttgart', 207.33], | ||
['Düsseldorf', 217.41], | ||
['Bremen', 326.7], | ||
['Dresden', 328.8], | ||
['Hannover', 204.007], | ||
['Wiesbaden', 203.9], | ||
['Kiel', 118.6], | ||
['Magdeburg', 201.012], | ||
['Mainz', 97.7], | ||
['Erfurt', 269.2], | ||
] | ||
|
||
locale.setlocale(locale.LC_ALL, 'de_DE') | ||
|
||
text = '\t<span font_weight="bold">Name</span>' \ | ||
'\t<span font_weight="bold"> Fläche (km²)</span>\n' | ||
for line in lines: | ||
text += "\t" + line[0] | ||
text += "\t" + locale.format_string("%f", line[1])\ | ||
.rstrip('0').rstrip(',') | ||
text += '\n' | ||
|
||
# Using pangocairocffi, this would be `pangocairocffi.create_layout()` with | ||
# a cairocffi context object. | ||
layout = Layout.from_pointer( | ||
pangocairo.pango_cairo_create_layout(cairo_context) | ||
) | ||
|
||
mm_to_inches = 72 / 25.4 | ||
|
||
layout.width = pangocffi.units_from_double(width * mm_to_inches) | ||
layout.apply_markup(text) | ||
|
||
# With this configuration, the tabs will align the text at 30mm and 70mm | ||
# intervals. In more simple terms: The first items that are tabbed should | ||
# appear right-aligned at the 30mm position, and all ',' (which will | ||
# be part of a number) should appear at the 70mm position. | ||
tabarray = TabArray() | ||
tabarray.tabs = [ | ||
(TabAlign.RIGHT, pangocffi.units_from_double(30 * mm_to_inches)), | ||
(TabAlign.DECIMAL, pangocffi.units_from_double(45 * mm_to_inches)) | ||
] | ||
decimal_point = [None, ','] | ||
tabarray.decimal_point = decimal_point | ||
|
||
layout.tabs = tabarray | ||
|
||
# Using pangocairocffi, this would be `pangocairocffi.show_layout(layout)` | ||
pangocairo.pango_cairo_show_layout(cairo_context, layout.pointer) | ||
|
||
context_creator.close() |
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
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,43 @@ | ||
from pangocffi import ( | ||
TabArray, TabAlign | ||
) | ||
import unittest | ||
|
||
|
||
class TestTabArray(unittest.TestCase): | ||
def test_identity(self): | ||
tab_array = TabArray() | ||
assert len(tab_array) == 0 | ||
tabs = [(TabAlign.LEFT, 1), (TabAlign.LEFT, 10)] | ||
tab_array.tabs = tabs | ||
assert len(tab_array) == len(tabs) | ||
assert tab_array.tabs == tabs | ||
|
||
decimal_point = [':', ','] | ||
tab_array.decimal_point = decimal_point | ||
assert tab_array.decimal_point == decimal_point | ||
|
||
assert tab_array.positions_in_pixels is False | ||
tab_array.positions_in_pixels = True | ||
assert tab_array.positions_in_pixels is True | ||
|
||
def test_zero_size(self): | ||
tab_array = TabArray() | ||
assert len(tab_array) == 0 | ||
assert tab_array.tabs == [] | ||
|
||
def test_decimal_point_none(self): | ||
tab_array = TabArray() | ||
|
||
tabs = [(TabAlign.LEFT, 1), (TabAlign.LEFT, 10)] | ||
tab_array.tabs = tabs | ||
decimal_point = [None, None] | ||
tab_array.decimal_point = decimal_point | ||
assert tab_array.decimal_point == decimal_point | ||
|
||
def test_decimal_point_index_error(self): | ||
tab_array = TabArray() | ||
|
||
tab_array.tabs = [(TabAlign.LEFT, 1), (TabAlign.LEFT, 10)] | ||
with self.assertRaises(IndexError): | ||
tab_array.decimal_point = [','] |
This file was deleted.
Oops, something went wrong.