Skip to content

Commit

Permalink
Merge pull request #3 from TAlonglong/fork/develop
Browse files Browse the repository at this point in the history
Fork/develop
  • Loading branch information
djhoese committed Nov 3, 2018
2 parents 1f1a181 + 716d5b0 commit 7f46ef6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
3 changes: 0 additions & 3 deletions pydecorate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,3 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from pydecorate.decorator_agg import DecoratorAGG



7 changes: 7 additions & 0 deletions pydecorate/decorator_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ def _load_default_font(self):
font_path = resource_filename('pydecorate.fonts', 'DejaVuSerif.ttf')
return aggdraw.Font('black', font_path, size=16)

def _load_font(self):
import aggdraw
try:
return aggdraw.Font(self.style['line'], self.style['font'], self.style['font_size'])
except IOError:
raise

def add_text(self, txt, **kwargs):
self._add_text(txt, **kwargs)

Expand Down
25 changes: 23 additions & 2 deletions pydecorate/decorator_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
'fill': 'black',
'fill_opacity': 255,
'font': None,
'font_size': 16,
'start_border': [0, 0],
'extend': False,
'tick_marks': 1.0,
Expand Down Expand Up @@ -225,16 +226,35 @@ def _draw_text(self, draw, xy, txt, font, fill='black', align='cc', dry_run=Fals

return tw, th

def _check_align(self):
if 'align' in self.style:
if 'top_bottom' in self.style['align']:
if self.style['align']['top_bottom'] == 'top':
self.align_top()
elif self.style['align']['top_bottom'] == 'bottom':
self.align_bottom()
if 'left_right' in self.style['align']:
if self.style['align']['left_right'] == 'left':
self.align_left()
elif self.style['align']['left_right'] == 'right':
self.align_right()

def _get_current_font(self):
if self.style['font'] is None:
self.style['font'] = self._load_default_font()
else:
self.style['font'] = self._load_font()

def _add_text(self, txt, **kwargs):
# synchronize kwargs into style
self.set_style(**kwargs)
self._check_align()

# draw object
draw = self._get_canvas(self.image)

# check for font object
if self.style['font'] is None:
self.style['font'] = self._load_default_font()
self._get_current_font()

# image size
x_size, y_size = self.image.size
Expand Down Expand Up @@ -306,6 +326,7 @@ def _draw_rectangle(self, draw, xys, **kwargs):
def _add_logo(self, logo_path, **kwargs):
# synchronize kwargs into style
self.set_style(**kwargs)
self._check_align()

# current xy and margins
x = self.style['cursor'][0]
Expand Down
9 changes: 2 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,12 @@
"Operating System :: OS Independent",
"Programming Language :: Python",
"Topic :: Scientific/Engineering"],
url="http://code.google.com/p/pydecorate/",
# download_url="..."
url="https://github.com/pytroll/pydecorate",
long_description=long_description,
license='GPLv3',

packages=['pydecorate'],
include_package_data=True,
package_data={'pydecorate': ['fonts/*.ttf']},

# Project should use reStructuredText, so ensure that the docutils get
# installed or upgraded on the target machine
install_requires=['pillow', 'aggdraw'],
Expand All @@ -62,6 +59,4 @@
# test_suite="",
tests_require=['pytest', 'mock'],
python_requires='>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*',

zip_safe=False
)
zip_safe=False)

0 comments on commit 7f46ef6

Please sign in to comment.