@@ -10,6 +10,7 @@ import fontTools.pens.basePen
|
||||
|
||||
import generator.engraving.fonts
|
||||
import generator.engraving.types
|
||||
import generator.theme
|
||||
|
||||
class OutlinePen(fontTools.pens.basePen.BasePen):
|
||||
def __init__(self, glyphs, scale: float, x: float, y: float):
|
||||
@@ -34,7 +35,7 @@ def rasterize_page(page: generator.engraving.types.Page, fonts: generator.engrav
|
||||
|
||||
def rasterize_band(page: generator.engraving.types.Page, primitives: tuple[generator.engraving.types.Primitive, ...], top: int, bottom: int, fonts: generator.engraving.fonts.Fonts) -> PIL.Image.Image:
|
||||
scale = page.supersampling
|
||||
image = PIL.Image.new('RGB', (page.width * scale, (bottom - top) * scale), 'white')
|
||||
image = PIL.Image.new('RGB', (page.width * scale, (bottom - top) * scale), generator.theme.rgb('background'))
|
||||
context = aggdraw.Draw(image)
|
||||
for item in primitives:
|
||||
points = [(x * scale, y * scale - top * scale) for x, y in item.points]
|
||||
@@ -55,15 +56,15 @@ def rasterize_band(page: generator.engraving.types.Page, primitives: tuple[gener
|
||||
if item.kind == 'polygon':
|
||||
path.close()
|
||||
if item.kind in ('glyph', 'polygon'):
|
||||
context.path(path, None, aggdraw.Brush('black'))
|
||||
context.path(path, None, aggdraw.Brush(generator.theme.rgb('ink')))
|
||||
else:
|
||||
context.path(path, aggdraw.Pen('black', item.thickness * scale))
|
||||
context.path(path, aggdraw.Pen(generator.theme.rgb('ink'), item.thickness * scale))
|
||||
context.flush()
|
||||
drawing = PIL.ImageDraw.Draw(image)
|
||||
for item in primitives:
|
||||
if item.kind == 'text':
|
||||
x, y = item.points[0]
|
||||
drawing.text((x * scale, y * scale - top * scale), item.value, font=fonts.text_font(item.size * scale), anchor='ls', fill='black')
|
||||
drawing.text((x * scale, y * scale - top * scale), item.value, font=fonts.text_font(item.size * scale), anchor='ls', fill=generator.theme.rgb('ink'))
|
||||
return image.resize((page.width, bottom - top), PIL.Image.Resampling.LANCZOS)
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
@@ -75,7 +76,7 @@ class Band:
|
||||
def page_bands(page: generator.engraving.types.Page) -> tuple[Band, Band, Band] | None:
|
||||
body = tuple(p for system in page.systems for p in system.primitives)
|
||||
header = tuple(p for p in page.primitives if p.role in ('title', 'subtitle'))
|
||||
footer = tuple(p for p in page.primitives if p.role == 'page-number')
|
||||
footer = tuple(p for p in page.primitives if p.role == 'page_number')
|
||||
if not body or not header or not footer or page.primitives != header + body + footer:
|
||||
return None
|
||||
bands = []
|
||||
@@ -91,7 +92,7 @@ def page_bands(page: generator.engraving.types.Page) -> tuple[Band, Band, Band]
|
||||
return tuple(bands)
|
||||
|
||||
def compose_page(page: generator.engraving.types.Page, fonts: generator.engraving.fonts.Fonts, bands: tuple[Band, Band, Band], body: PIL.Image.Image) -> PIL.Image.Image:
|
||||
image = PIL.Image.new('RGB', (page.width, page.height), 'white')
|
||||
image = PIL.Image.new('RGB', (page.width, page.height), generator.theme.rgb('background'))
|
||||
if body.mode != 'RGB' or body.size != (page.width, bands[1].bottom - bands[1].top):
|
||||
raise generator.engraving.types.EngravingError('notation band has incompatible geometry')
|
||||
image.paste(body, (0, bands[1].top))
|
||||
|
||||
Reference in New Issue
Block a user