diff --git a/uppsrc/RichText/RichText.h b/uppsrc/RichText/RichText.h index d38e47590..7a21b5ab6 100644 --- a/uppsrc/RichText/RichText.h +++ b/uppsrc/RichText/RichText.h @@ -490,6 +490,10 @@ struct PrintPageDraw : PageDraw { virtual ~PrintPageDraw() {} }; +Array RenderPages(const RichText& txt, Size pagesize = Size(3968, 6074)); + +String Pdf(const RichText& txt, Size pagesize = Size(3968, 6074), int margin = 200, bool pdfa = false); + END_UPP_NAMESPACE #endif diff --git a/uppsrc/RichText/Util.cpp b/uppsrc/RichText/Util.cpp index f0125a293..3fbd64a67 100644 --- a/uppsrc/RichText/Util.cpp +++ b/uppsrc/RichText/Util.cpp @@ -133,4 +133,58 @@ RichText AsRichText(const wchar *s, const RichPara::Format& f) return clip; } +struct DrawingPageDraw__ : public DrawingDraw, public PageDraw { + virtual Draw& Page(int i); + + Array page; + int pagei; + Size size; + + void Flush(); + + DrawingPageDraw__() { pagei = -1; } +}; + +Draw& DrawingPageDraw__::Page(int i) +{ + ASSERT(i >= 0); + if(i != pagei) { + Flush(); + pagei = i; + Create(size); + } + return *this; +} + +void DrawingPageDraw__::Flush() +{ + if(pagei >= 0) { + Drawing dw = GetResult(); + page.At(pagei).Append(dw); + Create(size); + } +} + +Array RenderPages(const RichText& txt, Size pagesize) +{ + DrawingPageDraw__ pd; + pd.size = pagesize; + PageY py(0, 0); + PaintInfo paintinfo; + paintinfo.top = PageY(0, 0); + paintinfo.bottom = PageY(INT_MAX, INT_MAX); + paintinfo.indexentry = Null; + paintinfo.hyperlink = Null; + txt.Paint(pd, PageY(0, 0), pagesize, paintinfo); + pd.Flush(); + return pd.page; +} + +String Pdf(const RichText& txt, Size pagesize, int margin, bool pdfa) +{ + Array pages = RenderPages(txt, pagesize); + return GetDrawingToPdfFn() && pages.GetCount() ? (*GetDrawingToPdfFn())(pages, pagesize, margin, pdfa) + : String(); +} + END_UPP_NAMESPACE