From b092214210883080ad4d31e851d33d68ba2d795f Mon Sep 17 00:00:00 2001 From: Trygve Aspenes Date: Thu, 23 Nov 2017 13:50:04 +0000 Subject: [PATCH 1/6] .gitignore added build and dist --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 35348e7..e79cff7 100644 --- a/.gitignore +++ b/.gitignore @@ -87,3 +87,5 @@ /pydecorate_old/colormap/__init__.pyc /pydecorate_old/__init__.py~ /pydecorate_old/__init__.pyc +/build +/dist From afeb8b484f601d529638634c8794265415bf7415 Mon Sep 17 00:00:00 2001 From: Trygve Aspenes Date: Thu, 23 Nov 2017 13:51:14 +0000 Subject: [PATCH 2/6] pydecorate/decorator_agg.py added load_font function to be able to load a specified font when loaded from outside --- pydecorate/decorator_agg.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pydecorate/decorator_agg.py b/pydecorate/decorator_agg.py index 009f6fe..27ac812 100644 --- a/pydecorate/decorator_agg.py +++ b/pydecorate/decorator_agg.py @@ -35,6 +35,13 @@ def _load_default_font(self): except IOError: return aggdraw.Font("black", "/usr/share/fonts/dejavu/DejaVuSerif.ttf", 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) From 33b5063e191480eb3949f3ccfa962157a6a4089a Mon Sep 17 00:00:00 2001 From: Trygve Aspenes Date: Thu, 23 Nov 2017 13:53:49 +0000 Subject: [PATCH 3/6] pydecorate/decorator_base.py added style:font_size. Added in add_text to align text according as given in style. Added load font if style['font'] is not None ie a file. --- pydecorate/decorator_base.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pydecorate/decorator_base.py b/pydecorate/decorator_base.py index 619bfe3..1b7ed7b 100644 --- a/pydecorate/decorator_base.py +++ b/pydecorate/decorator_base.py @@ -49,6 +49,7 @@ 'fill': 'black', 'fill_opacity': 255, 'font': None, + 'font_size': 16, 'start_border': [0, 0], 'extend': False, 'tick_marks': 1.0, @@ -229,12 +230,26 @@ def _add_text(self, txt, **kwargs): # synchronize kwargs into style self.set_style(**kwargs) + 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() + # 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() + else: + self.style['font'] = self._load_font() # image size x_size, y_size = self.image.size From 28fb2d11c9889d3533bda32d24caf6781b28e35c Mon Sep 17 00:00:00 2001 From: Trygve Aspenes Date: Fri, 24 Nov 2017 09:09:29 +0000 Subject: [PATCH 4/6] pydecorate/decorator_base.py add handeling of config given alignment of logos --- pydecorate/decorator_base.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pydecorate/decorator_base.py b/pydecorate/decorator_base.py index 1b7ed7b..fa11707 100644 --- a/pydecorate/decorator_base.py +++ b/pydecorate/decorator_base.py @@ -322,6 +322,18 @@ def _add_logo(self, logo_path, **kwargs): # synchronize kwargs into style self.set_style(**kwargs) + 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() + # current xy and margins x = self.style['cursor'][0] y = self.style['cursor'][1] From d4ae8bdd48b7300f7d0b31e9ac10d55f9fc5f465 Mon Sep 17 00:00:00 2001 From: David Hoese Date: Fri, 2 Nov 2018 20:15:08 -0500 Subject: [PATCH 5/6] Update project URL in setup.py --- setup.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/setup.py b/setup.py index bba12b1..5587267 100644 --- a/setup.py +++ b/setup.py @@ -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'], @@ -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) From 716d5b0a3e17aec2821cc924a6bcf8ce8974313a Mon Sep 17 00:00:00 2001 From: David Hoese Date: Fri, 2 Nov 2018 20:24:04 -0500 Subject: [PATCH 6/6] Move new alignment handling in to separate method --- pydecorate/__init__.py | 3 --- pydecorate/decorator_base.py | 34 ++++++++++++++-------------------- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/pydecorate/__init__.py b/pydecorate/__init__.py index 2fc9dd1..72bbfe5 100644 --- a/pydecorate/__init__.py +++ b/pydecorate/__init__.py @@ -17,6 +17,3 @@ # along with this program. If not, see . from pydecorate.decorator_agg import DecoratorAGG - - - diff --git a/pydecorate/decorator_base.py b/pydecorate/decorator_base.py index d8ae353..1920105 100644 --- a/pydecorate/decorator_base.py +++ b/pydecorate/decorator_base.py @@ -226,10 +226,7 @@ def _draw_text(self, draw, xy, txt, font, fill='black', align='cc', dry_run=Fals return tw, th - def _add_text(self, txt, **kwargs): - # synchronize kwargs into style - self.set_style(**kwargs) - + def _check_align(self): if 'align' in self.style: if 'top_bottom' in self.style['align']: if self.style['align']['top_bottom'] == 'top': @@ -242,15 +239,23 @@ def _add_text(self, txt, **kwargs): elif self.style['align']['left_right'] == 'right': self.align_right() - # draw object - draw = self._get_canvas(self.image) - - # check for font object + 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 + self._get_current_font() + # image size x_size, y_size = self.image.size @@ -321,18 +326,7 @@ def _draw_rectangle(self, draw, xys, **kwargs): def _add_logo(self, logo_path, **kwargs): # synchronize kwargs into style self.set_style(**kwargs) - - 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() + self._check_align() # current xy and margins x = self.style['cursor'][0]