[gnome-maps/wip/mlundblad/dont-use-offscreen-window] WIP: transitPrintLayout: Use Cairo and Pango to render
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/mlundblad/dont-use-offscreen-window] WIP: transitPrintLayout: Use Cairo and Pango to render
- Date: Thu, 21 Mar 2019 22:14:54 +0000 (UTC)
commit c8ea0411585b27a9184f566613291c38295c75a5
Author: Marcus Lundblad <ml update uu se>
Date: Sun Mar 17 22:22:29 2019 +0100
WIP: transitPrintLayout: Use Cairo and Pango to render
src/transitPrintLayout.js | 81 +++++++++++++++++++++++++++++++++++++++--------
1 file changed, 67 insertions(+), 14 deletions(-)
---
diff --git a/src/transitPrintLayout.js b/src/transitPrintLayout.js
index 5648390..b8d14a7 100644
--- a/src/transitPrintLayout.js
+++ b/src/transitPrintLayout.js
@@ -25,9 +25,13 @@ const Clutter = imports.gi.Clutter;
const Gdk = imports.gi.Gdk;
const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
+const Pango = imports.gi.Pango;
+const Color = imports.color;
+const Gfx = imports.gfx;
const MapSource = imports.mapSource;
const PrintLayout = imports.printLayout;
+const Transit = imports.transit;
const TransitArrivalMarker = imports.transitArrivalMarker;
const TransitArrivalRow = imports.transitArrivalRow;
const TransitBoardMarker = imports.transitBoardMarker;
@@ -59,6 +63,9 @@ const _Instruction = {
SCALE_MARGIN: 0.01
};
+// luminance threashhold for drawing outline around route label badges
+const OUTLINE_LUMINANCE_THREASHHOLD = 0.9;
+
var TransitPrintLayout = GObject.registerClass(
class TransitPrintLayout extends PrintLayout.PrintLayout {
@@ -214,24 +221,70 @@ class TransitPrintLayout extends PrintLayout.PrintLayout {
}
_drawInstruction(width, height, leg, start) {
- let legRow = new TransitLegRow.TransitLegRow({
- visible: true,
- leg: leg,
- start: start,
- print: true
- });
+ let pageNum = this.numPages - 1;
+ let x = this._cursorX;
+ let y = this._cursorY;
+ let surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, width, height);
+ let cr = new Cairo.Context(surface);
+ let timeWidth = !leg.transit && start ? height : height * 2;
+ let fromText = Transit.getFromLabel(leg, start);
+ let routeWidth = 0;
+
+ this._drawIcon(cr, leg.iconName, width, height);
+ this._drawText(cr, fromText, width - height - timeWidth, height / 2,
+ this._rtl ? timeWidth : height, 0, Pango.Alignment.LEFT);
+
+ if (leg.transit) {
+ let color = leg.color;
+ let textColor = leg.textColor;
+ let hasOutline = Color.relativeLuminance(color) > OUTLINE_LUMINANCE_THREASHHOLD;
+ let routeText =
+ this._createTextLayout(cr, leg.route, width - height - timeWidth,
+ height / 2, Pango.Alignment.LEFT);
+ let [pWidth, pHeight] = routeText.get_pixel_size();
+ let routeHeight = pHeight;
+
+ routeWidth = Math.max(pWidth, pHeight);
+ textColor = Color.getContrastingForegroundColor(textColor, color);
+ cr.moveTo(this._rtl ? width - height - routeWidth - 1 :
+ height + routeWidth,
+ height / 2 + ((height / 2) - routeHeight) / 2);
+ Gfx.drawColoredBagde(cr, color, hasOutline ? textColor : null,
+ routeWidth, routeHeight);
+
+ }
- this._renderWidget(legRow, width, height);
+ this._drawTextVerticallyCentered(cr, leg.prettyPrintTime({ start: start }),
+ timeWidth, height,
+ this._rtl ? 0 : width - timeWidth - 1,
+ this._rtl ? Pango.Alignment.LEFT :
+ Pango.Alignment.RIGHT);
+
+ this._addSurface(surface, x, y, pageNum);
}
_drawArrival(width, height) {
- let arrivalRow = new TransitArrivalRow.TransitArrivalRow({
- visible: true,
- itinerary: this._itinerary,
- print: true
- });
-
- this._renderWidget(arrivalRow, width, height);
+ let pageNum = this.numPages - 1;
+ let x = this._cursorX;
+ let y = this._cursorY;
+ let surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, width, height);
+ let cr = new Cairo.Context(surface);
+ let lastLeg = this._itinerary.legs[this._itinerary.legs.length - 1];
+
+ this._drawIcon(cr, 'maps-point-end-symbolic', width, height);
+ // draw the arrival text
+ this._drawTextVerticallyCentered(cr, Transit.getArrivalLabel(lastLeg),
+ width - height * 2,
+ height, this._rtl ? height * 2 : height,
+ Pango.Alignment.LEFT);
+ // draw arrival time
+ this._drawTextVerticallyCentered(cr, lastLeg.prettyPrintArrivalTime(),
+ height, height,
+ this._rtl ? 0 : width - height - 1,
+ this._rtl ? Pango.Alignment.LEFT :
+ Pango.Alignment.RIGHT);
+
+ this._addSurface(surface, x, y, pageNum);
}
_legHasMiniMap(index) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]