NMEA2000-Code weiterbearbeitet
This commit is contained in:
@@ -167,36 +167,67 @@ class Page():
|
||||
ctx.fill()
|
||||
ctx.set_source_rgb(0, 0, 0)
|
||||
|
||||
def draw_text_center(self, ctx, x, y, content, rotate=False, baseline=False, fill=False):
|
||||
ext = ctx.text_extents(content)
|
||||
def draw_text_center(self, ctx, x, y, content, rotate=False, baseline=False, fill=False, fix1=False):
|
||||
"""
|
||||
Korrektur für DSEG7: Die Breite der 1 ist gleich 0.289 * Breite der anderen Ziffern
|
||||
Da der Leerraum bei der Ausgabe mit berücksichtigt wird, muß die tatsächliche
|
||||
Ausgabeposition links von der Mitte sein um (1 - 0.289) * Breite (=0.711)
|
||||
Zusätzlich muß der Abstand zwischen der 1 und dem nachfolgenden Zeichen berücksichtigt
|
||||
werden
|
||||
"""
|
||||
if fix1 and content[0] == '1':
|
||||
print("Fix1")
|
||||
ext1 = ctx.text_extents('1')
|
||||
w1 = 0.289 * ext1.width
|
||||
dx = ext1.width - w1
|
||||
ext = ctx.text_extents(content[1:])
|
||||
else:
|
||||
ext = ctx.text_extents(content)
|
||||
if fill:
|
||||
ctx.set_source_rgb(*self.bgcolor)
|
||||
xf = x + ext.x_bearing - 2
|
||||
yf = y + ext.height / 2 + ext.y_bearing - 2
|
||||
wf = ext.width + 4
|
||||
if fix1:
|
||||
wf += w1
|
||||
hf = ext.height + 4
|
||||
ctx.rectangle(xf, yf, wf, hf)
|
||||
ctx.fill()
|
||||
ctx.set_source_rgb(*self.fgcolor)
|
||||
if rotate:
|
||||
w = ext[2]
|
||||
if fix1 and content[0] == '1':
|
||||
w += w1
|
||||
x = x - dx
|
||||
if baseline:
|
||||
ctx.move_to(x - ext[3] / 2.0, y)
|
||||
ctx.move_to(x - w / 2.0, y)
|
||||
else:
|
||||
ctx.move_to(x - ext[3] / 2.0, y + ext[2] / 2.0)
|
||||
ctx.move_to(x - w / 2.0, y + ext[2] / 2.0)
|
||||
ctx.save()
|
||||
ctx.rotate(1.5 * math.pi)
|
||||
ctx.show_text(content)
|
||||
ctx.restore()
|
||||
else:
|
||||
w = ext.width
|
||||
if fix1 and content[0] == '1':
|
||||
w += w1
|
||||
x = x - dx
|
||||
if baseline:
|
||||
ctx.move_to(x - ext[2] / 2.0, y)
|
||||
ctx.move_to(x - w / 2.0, y)
|
||||
else:
|
||||
ctx.move_to(x - ext[2] / 2.0, y + ext[3] / 2.0)
|
||||
ctx.move_to(x - w / 2.0, y + ext[3] / 2.0)
|
||||
ctx.show_text(content)
|
||||
ctx.stroke()
|
||||
|
||||
def draw_text_ralign(self, ctx, x, y, content):
|
||||
ext = ctx.text_extents(content)
|
||||
ctx.move_to(x - ext[2], y)
|
||||
def draw_text_ralign(self, ctx, x, y, content, fix1=False):
|
||||
if fix1 and content[0] == '1':
|
||||
w1 = ctx.text_extents('1')[2] * 0.289
|
||||
ext = ctx.text_extents(content[1:])
|
||||
w = ext[2] + w1
|
||||
x = x - dx
|
||||
else:
|
||||
ext = ctx.text_extents(content)
|
||||
w = ext[2]
|
||||
ctx.move_to(x - w, y)
|
||||
ctx.show_text(content)
|
||||
ctx.stroke()
|
||||
|
||||
Reference in New Issue
Block a user