diff --git a/src/generic/genericuic918extractor.cpp b/src/generic/genericuic918extractor.cpp index 5ea7a32..00c8775 100644 --- a/src/generic/genericuic918extractor.cpp +++ b/src/generic/genericuic918extractor.cpp @@ -1,121 +1,116 @@ /* Copyright (C) 2018-2019 Volker Krause This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "genericuic918extractor_p.h" +#include #include #include #include #include #include #include using namespace KItinerary; void GenericUic918Extractor::extract(const QByteArray &data, QJsonArray &result, const QDateTime &contextDate) { Uic9183Parser p; p.setContextDate(contextDate); p.parse(data); if (!p.isValid()) { return; } QJsonObject org; org.insert(QStringLiteral("@type"), QLatin1String("Organization")); org.insert(QStringLiteral("identifier"), QString(QLatin1String("uic:") + p.carrierId())); QJsonObject trip; trip.insert(QStringLiteral("@type"), QLatin1String("TrainTrip")); trip.insert(QStringLiteral("provider"), org); QJsonObject seat; seat.insert(QStringLiteral("@type"), QLatin1String("Seat")); + seat.insert(QStringLiteral("seatingType"), p.seatingType()); const auto rct2 = p.rct2Ticket(); if (rct2.isValid()) { switch (rct2.type()) { case Rct2Ticket::Reservation: case Rct2Ticket::TransportReservation: { trip.insert(QStringLiteral("trainNumber"), rct2.trainNumber()); seat.insert(QStringLiteral("seatSection"), rct2.coachNumber()); seat.insert(QStringLiteral("seatNumber"), rct2.seatNumber()); Q_FALLTHROUGH(); } case Rct2Ticket::Transport: case Rct2Ticket::Upgrade: { QJsonObject dep; dep.insert(QStringLiteral("@type"), QLatin1String("TrainStation")); dep.insert(QStringLiteral("name"), rct2.outboundDepartureStation()); trip.insert(QStringLiteral("departureStation"), dep); QJsonObject arr; arr.insert(QStringLiteral("@type"), QLatin1String("TrainStation")); arr.insert(QStringLiteral("name"), rct2.outboundArrivalStation()); trip.insert(QStringLiteral("arrivalStation"), arr); if (rct2.outboundDepartureTime().isValid()) { trip.insert(QStringLiteral("departureDay"), rct2.outboundDepartureTime().date().toString(Qt::ISODate)); } else { trip.insert(QStringLiteral("departureDay"), rct2.firstDayOfValidity().toString(Qt::ISODate)); } if (rct2.outboundDepartureTime() != rct2.outboundArrivalTime()) { trip.insert(QStringLiteral("departureTime"), rct2.outboundDepartureTime().toString(Qt::ISODate)); trip.insert(QStringLiteral("arrivalTime"), rct2.outboundArrivalTime().toString(Qt::ISODate)); } - seat.insert(QStringLiteral("seatingType"), rct2.outboundClass()); break; } default: break; } } QJsonObject ticket; ticket.insert(QStringLiteral("@type"), QLatin1String("Ticket")); ticket.insert(QStringLiteral("ticketToken"), QString(QLatin1String("aztecbin:") + QString::fromLatin1(data.toBase64()))); ticket.insert(QStringLiteral("ticketedSeat"), seat); switch (rct2.type()) { // provide names for typically "addon" tickets, so we can distinguish them in the UI case Rct2Ticket::Reservation: ticket.insert(QStringLiteral("name"), i18n("Reservation")); break; case Rct2Ticket::Upgrade: ticket.insert(QStringLiteral("name"), i18n("Upgrade")); break; default: break; } - QJsonObject person; - person.insert(QStringLiteral("@type"), QLatin1String("Person")); - if (!rct2.passengerName().isEmpty()) { - person.insert(QStringLiteral("name"), rct2.passengerName()); - } - QJsonObject res; res.insert(QStringLiteral("@type"), QLatin1String("TrainReservation")); res.insert(QStringLiteral("reservationFor"), trip); res.insert(QStringLiteral("reservationNumber"), p.pnr()); res.insert(QStringLiteral("reservedTicket"), ticket); - res.insert(QStringLiteral("underName"), person); + res.insert(QStringLiteral("underName"), JsonLdDocument::toJson(p.person())); result.push_back(res); } diff --git a/src/pdf/popplerutils.cpp b/src/pdf/popplerutils.cpp index ec7e628..e071e7a 100644 --- a/src/pdf/popplerutils.cpp +++ b/src/pdf/popplerutils.cpp @@ -1,109 +1,113 @@ /* Copyright (C) 2019 Volker Krause This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include "popplerutils_p.h" #include #include #include #include #ifdef HAVE_POPPLER #include using namespace KItinerary; QPen PopplerUtils::currentPen(GfxState *state) { QPen pen; pen.setStyle(Qt::SolidLine); pen.setWidthF(state->getLineWidth()); GfxRGB rgb; state->getStrokeRGB(&rgb); QColor c; c.setRgbF(colToDbl(rgb.r), colToDbl(rgb.g), colToDbl(rgb.b), 1.0f); pen.setColor(c); switch (state->getLineCap()) { case 0: pen.setCapStyle(Qt::FlatCap); break; case 1: pen.setCapStyle(Qt::RoundCap); break; case 2: pen.setCapStyle(Qt::SquareCap); break; } switch (state->getLineJoin()) { case 0: pen.setJoinStyle(Qt::SvgMiterJoin); break; case 1: pen.setJoinStyle(Qt::RoundJoin); break; case 2: pen.setJoinStyle(Qt::BevelJoin); break; } pen.setMiterLimit(state->getMiterLimit()); return pen; } QBrush PopplerUtils::currentBrush(GfxState* state) { QBrush brush; brush.setStyle(Qt::SolidPattern); GfxRGB rgb; state->getFillRGB(&rgb); QColor c; c.setRgbF(colToDbl(rgb.r), colToDbl(rgb.g), colToDbl(rgb.b), 1.0f); brush.setColor(c); return brush; } QTransform KItinerary::PopplerUtils::currentTransform(GfxState *state) { const auto ctm = state->getCTM(); return QTransform(ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]); } -QPainterPath PopplerUtils::convertPath(GFXPATH_CONST GfxPath *path, Qt::FillRule fillRule) +QPainterPath PopplerUtils::convertPath(const GfxPath *path, Qt::FillRule fillRule) { QPainterPath qpp; qpp.setFillRule(fillRule); for (auto i = 0; i < path->getNumSubpaths(); ++i) { +#if KPOPPLER_VERSION >= QT_VERSION_CHECK(0, 83, 0) const auto subpath = path->getSubpath(i); +#else + const auto subpath = const_cast(path)->getSubpath(i); +#endif if (subpath->getNumPoints() > 0) { qpp.moveTo(subpath->getX(0), subpath->getY(0)); for (auto j = 1;j < subpath->getNumPoints();) { if (subpath->getCurve(j)) { qpp.cubicTo(subpath->getX(j), subpath->getY(j), subpath->getX(j+1), subpath->getY(j+1), subpath->getX(j+2), subpath->getY(j+2)); j += 3; } else { qpp.lineTo(subpath->getX(j), subpath->getY(j)); ++j; } } if (subpath->isClosed()) { qpp.closeSubpath(); } } } return qpp; } #endif diff --git a/src/pdf/popplerutils_p.h b/src/pdf/popplerutils_p.h index d808604..7421dc8 100644 --- a/src/pdf/popplerutils_p.h +++ b/src/pdf/popplerutils_p.h @@ -1,55 +1,49 @@ /* Copyright (C) 2019 Volker Krause This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef KITINERARY_POPPLERUTILS_P_H #define KITINERARY_POPPLERUTILS_P_H #include class GfxPath; class GfxState; class QBrush; class QPainterPath; class QPen; class QTransform; -#if KPOPPLER_VERSION >= QT_VERSION_CHECK(0, 83, 0) -#define GFXPATH_CONST const -#else -#define GFXPATH_CONST -#endif - namespace KItinerary { /** Utilities for interacting with Poppler. */ namespace PopplerUtils { /** Returns the current pen. */ QPen currentPen(GfxState *state); /** Retruns the current brush. */ QBrush currentBrush(GfxState *state); /** Returns the current transformation matrix. */ QTransform currentTransform(GfxState *state); /** Convets a Poppler path into a Qt path. */ - QPainterPath convertPath(GFXPATH_CONST GfxPath *path, Qt::FillRule fillRule); + QPainterPath convertPath(const GfxPath *path, Qt::FillRule fillRule); } } #endif // KITINERARY_POPPLERUTILS_P_H