mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-09-05 17:44:55 -06:00
RichText: RenderPages, Pdf
git-svn-id: svn://ultimatepp.org/upp/trunk@4197 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
dc1a41021d
commit
233ef9d5ae
2 changed files with 58 additions and 0 deletions
|
|
@ -490,6 +490,10 @@ struct PrintPageDraw : PageDraw {
|
|||
virtual ~PrintPageDraw() {}
|
||||
};
|
||||
|
||||
Array<Drawing> 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
|
||||
|
|
|
|||
|
|
@ -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<Drawing> 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<Drawing> 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<Drawing> pages = RenderPages(txt, pagesize);
|
||||
return GetDrawingToPdfFn() && pages.GetCount() ? (*GetDrawingToPdfFn())(pages, pagesize, margin, pdfa)
|
||||
: String();
|
||||
}
|
||||
|
||||
END_UPP_NAMESPACE
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue