Skip to content

Segmentation fault if providing font in grid via aggdraw and add_overlay_from_dict to save.dataset... #43

@peters77

Description

@peters77

Code Sample, a minimal, complete, and verifiable piece of code

font = aggdraw.Font('blue','/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf',
                    opacity=127, size = 40)
coast = {'coast_dir': '/home/test/software/',
         'color': (0, 0, 0), 'width': 1.5, 'resolution': 'i'}
grid  = {'grid': {'major_lonlat': (10,10), 'minor_lonlat': (2, 2),
        'outline': (255, 255, 0) , 'outline_opacity': 175,
        'width': 1.0, 'minor_width': 0.5, 'minor_is_tick': 1,
        'write_text': True, 'lat_placement': 'lr', 'lon_placement': 'b',
        'font': font}}
deco = [{'text': {'txt': 'MSG4', 
         'font': '/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf',
         'font_size': 20, 'height': 10, 'bg': 'white', 'bg_opacity': 127, 'line': 'black'}}]
        
new_scene.save_dataset(composite, imgdir + 'MSG-4.jpg', 
                       overlay = {**coast, **grid},
                       decorate = {'decorate': deco}, fill_value=0)

Problem description

Providing a font with color, type, opacity, and fontsize via aggdraw for grid used in save.dataset via add_overlay_from_dict throws a segmantation fault.

[INFO: 2020-05-25 17:32:26 : satpy.writers] Add coastlines and political borders to image.
Segmentation fault 

This works,

coast = {'coast_dir': '/home/test/software/',
         'color': (0, 0, 0), 'width': 1.5, 'resolution': 'i'}
grid  = {'grid': {'major_lonlat': (10,10), 'minor_lonlat': (2, 2),
        'outline': (255, 255, 0) , 'outline_opacity': 175,
        'width': 1.0, 'minor_width': 0.5, 'minor_is_tick': 1,
        'write_text': True, 'lat_placement': 'lr', 'lon_placement': 'b',                       
        'font': '/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf', 
        'font_size': 40, 'outline': 'blue'}}
deco = [{'text': {'txt': 'MSG4', 
         'font': '/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf',
         'font_size': 20, 'height': 10, 'bg': 'white', 'bg_opacity': 127, 'line': 'black'}}]
                       
new_scene.save_dataset(composite, imgdir + 'MSG-4.jpg', 
                       overlay = {**coast, **grid},
                       decorate = {'decorate': deco}, fill_value=0)

...but in

pycoast/pycoast/cw_base.py

Lines 863 to 869 in 59e981f

if isinstance(font, str):
if is_agg:
from aggdraw import Font
font = Font(outline, font, size=font_size)
else:
from PIL.ImageFont import truetype
font = truetype(font, font_size)

there seems to be a problem setting the opacity (not take into account?) and the font color for the grid labels seems to be the same as for the grid lines (outline)? So I'm not able to provide a different color for the grid lines and the grid lables any more. This was possible before (see font attributes providing via aggdraw) which seems now broken)?

Versions of Python, package at hand and relevant dependencies

aggdraw 1.3.11
pycoast 1.10.3+413.ga5996ec4
satpy 0.10.1.dev2650+gaedf4075
python 3.7
Linux version 4.9.0-9-amd64

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions