File indexing completed on 2024-12-29 04:51:05
0001 /* 0002 SPDX-FileCopyrightText: 2023 Volker Krause <vkrause@kde.org> 0003 SPDX-License-Identifier: LGPL-2.0-or-later 0004 */ 0005 0006 function parseOnePdfTicket(text) { 0007 let res = JsonLd.newTrainReservation(); 0008 const header = text.match(/(.*)\n +(\d{6})\n(.*)/); 0009 res.reservedTicket.ticketToken = 'qrcode:' + header[2]; 0010 res.reservedTicket.name = header[1] + header[3]; 0011 const trip = text.match(/(.*) +(\d\d:\d\d) +(.*) +(\d\d:\d\d)\n.* (\d{1,5}) +.*(\d\d\.\d\d.\d{4})/); 0012 res.reservationFor.departureStation.name = trip[1]; 0013 res.reservationFor.arrivalStation.name = trip[3]; 0014 res.reservationFor.arrivalTime = JsonLd.toDateTime(trip[6] + ' ' + trip[4], 'dd.MM.yyyy hh:mm', 'lv'); 0015 res.reservationFor.departureTime = JsonLd.toDateTime(trip[6] + ' ' + trip[2], 'dd.MM.yyyy hh:mm', 'lv'); 0016 res.reservationFor.trainNumber = trip[5]; 0017 ExtractorEngine.extractPrice(text, res); 0018 return res; 0019 } 0020 0021 function parsePdfTicket(pdf, node, triggerNode) { 0022 const page = pdf.pages[triggerNode.location]; 0023 if (page.width < 210) { 0024 return parseOnePdfTicket(page.text); 0025 } else { 0026 return [parseOnePdfTicket(page.textInRect(0.0, 0.0, 0.5, 1.0)), 0027 parseOnePdfTicket(page.textInRect(0.5, 0.0, 1.0, 1.0))]; 0028 } 0029 }