/* Records every librevenge callback a parser makes (libwps or libwpd; this copy is ../wps/src/recorder.h) as one JSON event, so * the page can rebuild the document (or spreadsheet) in TypeScript: the * on-screen view, HTML, plain text, DOCX, XLSX and CSV all come from the same * events. * * [["openParagraph",{"fo:text-align":"center",...}],["insertText","Hello"],["closeParagraph"],...] * * Property values are librevenge's own strings ("0.5in", "bold", base64 for * pictures); property-list vectors (tab stops, table columns) become arrays * of objects. * * SPDX-License-Identifier: MPL-2.0 */ #pragma once #include #include namespace jm { class Events { public: Events() { m_out = "["; } void event(const char *name); void event(const char *name, const librevenge::RVNGPropertyList &props); void text(const char *name, const librevenge::RVNGString &text); std::string finish() { return m_out + "]"; } private: void begin(const char *name); void props(const librevenge::RVNGPropertyList &props); std::string m_out; bool m_first = true; }; #define JM_EV0(method) void method() override { m_ev.event(#method); } #define JM_EV1(method) void method(const librevenge::RVNGPropertyList &p) override { m_ev.event(#method, p); } #define JM_COMMON \ JM_EV1(setDocumentMetaData) JM_EV1(startDocument) JM_EV0(endDocument) \ JM_EV1(definePageStyle) JM_EV1(defineEmbeddedFont) \ JM_EV1(openPageSpan) JM_EV0(closePageSpan) \ JM_EV1(openHeader) JM_EV0(closeHeader) JM_EV1(openFooter) JM_EV0(closeFooter) \ JM_EV1(defineParagraphStyle) JM_EV1(openParagraph) JM_EV0(closeParagraph) \ JM_EV1(defineCharacterStyle) JM_EV1(openSpan) JM_EV0(closeSpan) \ JM_EV1(openLink) JM_EV0(closeLink) \ JM_EV1(defineSectionStyle) JM_EV1(openSection) JM_EV0(closeSection) \ JM_EV0(insertTab) JM_EV0(insertSpace) JM_EV0(insertLineBreak) \ JM_EV1(insertField) \ JM_EV1(openOrderedListLevel) JM_EV1(openUnorderedListLevel) \ JM_EV0(closeOrderedListLevel) JM_EV0(closeUnorderedListLevel) \ JM_EV1(openListElement) JM_EV0(closeListElement) \ JM_EV1(openFootnote) JM_EV0(closeFootnote) \ JM_EV1(openComment) JM_EV0(closeComment) \ JM_EV1(openTextBox) JM_EV0(closeTextBox) \ JM_EV1(openTable) JM_EV1(openTableRow) JM_EV0(closeTableRow) \ JM_EV1(openTableCell) JM_EV0(closeTableCell) JM_EV1(insertCoveredTableCell) \ JM_EV0(closeTable) \ JM_EV1(openFrame) JM_EV0(closeFrame) JM_EV1(insertBinaryObject) \ JM_EV1(insertEquation) \ JM_EV1(openGroup) JM_EV0(closeGroup) JM_EV1(defineGraphicStyle) \ JM_EV1(drawRectangle) JM_EV1(drawEllipse) JM_EV1(drawPolygon) \ JM_EV1(drawPolyline) JM_EV1(drawPath) JM_EV1(drawConnector) \ void insertText(const librevenge::RVNGString &t) override { m_ev.text("insertText", t); } class TextRecorder : public librevenge::RVNGTextInterface { public: JM_COMMON JM_EV1(openEndnote) JM_EV0(closeEndnote) std::string result() { return m_ev.finish(); } private: Events m_ev; }; class SheetRecorder : public librevenge::RVNGSpreadsheetInterface { public: JM_COMMON JM_EV1(defineSheetNumberingStyle) JM_EV1(openSheet) JM_EV0(closeSheet) JM_EV1(openSheetRow) JM_EV0(closeSheetRow) JM_EV1(openSheetCell) JM_EV0(closeSheetCell) JM_EV1(defineChartStyle) JM_EV1(openChart) JM_EV0(closeChart) JM_EV1(openChartTextObject) JM_EV0(closeChartTextObject) JM_EV1(openChartPlotArea) JM_EV0(closeChartPlotArea) JM_EV1(insertChartAxis) JM_EV1(openChartSerie) JM_EV0(closeChartSerie) std::string result() { return m_ev.finish(); } private: Events m_ev; }; } // namespace jm