From ceffc48db98564cf105fb9cb24133d8d6fd62426 Mon Sep 17 00:00:00 2001 From: Michael Pfeiffer Date: Sat, 22 Mar 2003 08:47:20 +0000 Subject: [PATCH] - updated to use PDFlib 5.0.0b2 - added basic support for stroke/fill opacity (transparency) git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2991 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../pdf/source/AdvancedSettingsWindow.cpp | 20 + .../pdf/source/AdvancedSettingsWindow.h | 2 + .../drivers/pdf/source/DocInfoWindow.cpp | 404 ++--- .../print/drivers/pdf/source/DocInfoWindow.h | 61 +- .../print/drivers/pdf/source/DrawShape.cpp | 5 +- .../print/drivers/pdf/source/FontsWindow.cpp | 26 +- .../drivers/pdf/source/InterfaceUtils.cpp | 283 +++ .../print/drivers/pdf/source/InterfaceUtils.h | 117 ++ .../drivers/pdf/source/JobSetupWindow.cpp | 33 +- .../print/drivers/pdf/source/JobSetupWindow.h | 1 + .../drivers/pdf/source/PDFLinePathBuilder.h | 4 - .../print/drivers/pdf/source/PDFText.cpp | 5 + .../print/drivers/pdf/source/PDFWriter.cpp | 345 +++- .../print/drivers/pdf/source/PDFWriter.h | 44 +- .../drivers/pdf/source/PageSetupWindow.cpp | 14 +- .../drivers/pdf/source/PageSetupWindow.h | 1 + .../drivers/pdf/source/PrinterSettings.cpp | 32 +- .../drivers/pdf/source/PrinterSettings.h | 4 + .../drivers/pdf/source/PrinterSetupWindow.h | 1 + .../print/drivers/pdf/source/Report.cpp | 2 + .../print/drivers/pdf/source/StatusWindow.h | 1 + .../print/drivers/pdf/source/Utils.cpp | 116 +- src/add-ons/print/drivers/pdf/source/Utils.h | 25 +- src/add-ons/print/drivers/pdf/source/pdflib.h | 1608 ++++++++++------- 24 files changed, 2094 insertions(+), 1060 deletions(-) create mode 100644 src/add-ons/print/drivers/pdf/source/InterfaceUtils.cpp create mode 100644 src/add-ons/print/drivers/pdf/source/InterfaceUtils.h diff --git a/src/add-ons/print/drivers/pdf/source/AdvancedSettingsWindow.cpp b/src/add-ons/print/drivers/pdf/source/AdvancedSettingsWindow.cpp index 1460ca5ead..5787fa12f0 100644 --- a/src/add-ons/print/drivers/pdf/source/AdvancedSettingsWindow.cpp +++ b/src/add-ons/print/drivers/pdf/source/AdvancedSettingsWindow.cpp @@ -67,6 +67,18 @@ AdvancedSettingsWindow::AdvancedSettingsWindow(BMessage *settings) x = 5; y = 5; w = r.Width(); h = r.Height(); + // PDFlib license key +#if 0 + BString licenseKey; + if (settings->FindString("pdflib_license_key", &licenseKey) != B_OK) licenseKey = ""; + fLicenseKey = new BTextControl(BRect(x, y, x+2-10, y+14), "pdflib_license_key", "PDFlib License Key", "", NULL); + fLicenseKey->TextView()->HideTyping(true); + fLicenseKey->TextView()->SetText(licenseKey.String()); + panel->AddChild(fLicenseKey); + fLicenseKey->ResizeToPreferred(); + y += fLicenseKey->Bounds().Height()+5; +#endif + // web links if (settings->FindBool("create_web_links", &fCreateLinks) != B_OK) fCreateLinks = false; @@ -208,6 +220,14 @@ AdvancedSettingsWindow::AdvancedSettingsWindow(BMessage *settings) void AdvancedSettingsWindow::UpdateSettings() { +#if 0 + if (fSettings->HasString("pdflib_license_key")) { + fSettings->ReplaceString("pdflib_license_key", fLicenseKey->Text()); + } else { + fSettings->AddString("pdflib_license_key", fLicenseKey->Text()); + } +#endif + if (fSettings->HasBool("create_web_links")) { fSettings->ReplaceBool("create_web_links", fCreateLinks); } else { diff --git a/src/add-ons/print/drivers/pdf/source/AdvancedSettingsWindow.h b/src/add-ons/print/drivers/pdf/source/AdvancedSettingsWindow.h index 7a54bb77db..5eede0cf35 100644 --- a/src/add-ons/print/drivers/pdf/source/AdvancedSettingsWindow.h +++ b/src/add-ons/print/drivers/pdf/source/AdvancedSettingsWindow.h @@ -39,6 +39,7 @@ THE SOFTWARE. #include #include #include +#include "InterfaceUtils.h" #include "Utils.h" #include "PrinterDriver.h" @@ -73,6 +74,7 @@ private: BMessage* fSettings; + BTextControl* fLicenseKey; bool fCreateLinks; float fLinkBorderWidth; bool fCreateBookmarks; diff --git a/src/add-ons/print/drivers/pdf/source/DocInfoWindow.cpp b/src/add-ons/print/drivers/pdf/source/DocInfoWindow.cpp index fbbeb1191f..c06708f692 100644 --- a/src/add-ons/print/drivers/pdf/source/DocInfoWindow.cpp +++ b/src/add-ons/print/drivers/pdf/source/DocInfoWindow.cpp @@ -30,210 +30,53 @@ THE SOFTWARE. #include #include #include "DocInfoWindow.h" +#include "InterfaceUtils.h" #include - -// -------------------------------------------------- -class TextView : public BTextView -{ -public: - typedef BTextView inherited; - - TextView(BRect frame, - const char *name, - BRect textRect, - uint32 rmask = B_FOLLOW_LEFT | B_FOLLOW_TOP, - uint32 flags = B_WILL_DRAW | B_NAVIGABLE); - - TextView(BRect frame, - const char *name, - BRect textRect, - const BFont *font, const rgb_color *color, - uint32 rmask = B_FOLLOW_LEFT | B_FOLLOW_TOP, - uint32 flags = B_WILL_DRAW | B_NAVIGABLE); - - void KeyDown(const char *bytes, int32 numBytes); - void MakeFocus(bool focus = true); - void Draw(BRect r); +// pdflib 5.x supports password protection and permissions in the commercial license only! +static const PermissionLabels gPermissionLabels[] = { + PermissionLabels("Prevent printing the file.", "noprint"), + PermissionLabels("Prevent making any changes.", "nomodify"), + PermissionLabels("Prevent copying or extracting text or graphics.", "nocopy"), + PermissionLabels("Prevent adding or changing comments or form fields.", "noannots"), + PermissionLabels("Prevent form field filling.", "noforms"), + PermissionLabels("Prevent extracting text of graphics.", "noaccessible"), + PermissionLabels("Prevent inserting, deleting, or rotating pages and creating bookmarks and thumbnails, even if nomodify hasn't been specified", "noassemble"), + PermissionLabels("Prevent high-resolution printing.", "nohiresprint") }; +// Implementation of Permissions -// -------------------------------------------------- -class TextControl : public BView -{ - BStringView *fLabel; - TextView *fText; -public: - TextControl(BRect frame, - const char *name, - const char *label, - const char *initial_text, - BMessage *message, - uint32 rmask = B_FOLLOW_LEFT | B_FOLLOW_TOP, - uint32 flags = B_WILL_DRAW | B_NAVIGABLE); - const char *Label() { return fLabel->Text(); } - const char *Text() { return fText->Text(); } - void MakeFocus(bool focus = true) { fText->MakeFocus(focus); } - void ConvertToParent(BView* parent, BView* child, BRect &rect); - void FocusSetTo(BView* child); -}; - - -// -------------------------------------------------- -class Table : public BView -{ -public: - typedef BView inherited; - - Table(BRect frame, const char *name, uint32 rmode, uint32 flags); - void ScrollTo(BPoint p); -}; - - -// -------------------------------------------------- -TextView::TextView(BRect frame, - const char *name, - BRect textRect, - uint32 rmask, - uint32 flags) - : BTextView(frame, name, textRect, rmask, flags) -{ +Permissions::Permissions() { + fNofPermissions = sizeof(gPermissionLabels)/sizeof(PermissionLabels); + fPermissions = new Permission[fNofPermissions]; + for (int i = 0; i < fNofPermissions; i ++) { + fPermissions[i].SetLabels(&gPermissionLabels[i]); + } } - -// -------------------------------------------------- -TextView::TextView(BRect frame, - const char *name, - BRect textRect, - const BFont *font, const rgb_color *color, - uint32 rmask, - uint32 flags) - : BTextView(frame, name, textRect, font, color, rmask, flags) -{ -} - - -// -------------------------------------------------- -void -TextView::KeyDown(const char *bytes, int32 numBytes) -{ - if (numBytes == 1 && *bytes == B_TAB) { - BView::KeyDown(bytes, numBytes); - return; - } - inherited::KeyDown(bytes, numBytes); -} - - -// -------------------------------------------------- -void -TextView::Draw(BRect update) -{ - inherited::Draw(update); - if (IsFocus()) { - // stroke focus rectangle - SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR)); - StrokeRect(Bounds()); +void Permissions::Decode(const char* s) { + for (int i = 0; i < fNofPermissions; i ++) { + bool allowed = strstr(s, At(i)->GetPDFName()) == NULL; + At(i)->SetAllowed(allowed); } } - -// -------------------------------------------------- -void -TextView::MakeFocus(bool focus) -{ - Invalidate(); - inherited::MakeFocus(focus); - // notify TextControl - BView* parent = Parent(); // BBox - if (focus && parent) { - parent = parent->Parent(); // TextControl - TextControl* control = dynamic_cast(parent); - if (control) control->FocusSetTo(this); - } -} - - -// -------------------------------------------------- -TextControl::TextControl(BRect frame, - const char *name, - const char *label, - const char *initial_text, - BMessage *message, - uint32 rmask, - uint32 flags) - : BView(frame, name, rmask, flags) -{ - SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - BRect r(0, 0, frame.Width() / 2 -1, frame.Height()); - fLabel = new BStringView(r, "", label); - BRect f(r); - f.OffsetTo(frame.Width() / 2 + 1, 0); - // box around TextView - BBox *box = new BBox(f, "", B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW); - f.OffsetTo(0, 0); - f.InsetBy(1,1); - r.InsetBy(2,2); - fText = new TextView(f, "", r, rmask, flags | B_NAVIGABLE); - fText->SetWordWrap(false); - fText->DisallowChar('\n'); - fText->Insert(initial_text); - AddChild(fLabel); - AddChild(box); - box->AddChild(fText); -} - - -// -------------------------------------------------- -void -TextControl::ConvertToParent(BView* parent, BView* child, BRect &rect) -{ - do { - child->ConvertToParent(&rect); - child = child->Parent(); - } while (child != NULL && child != parent); -} - - -// -------------------------------------------------- -void -TextControl::FocusSetTo(BView *child) -{ - BRect r; - BView* parent = Parent(); // Table - if (parent) { - ConvertToParent(parent, child, r); - parent->ScrollTo(0, r.top); - } -} - - -// -------------------------------------------------- -Table::Table(BRect frame, const char *name, uint32 rmode, uint32 flags) - : BView(frame, name, rmode, flags) -{ -} - - -// -------------------------------------------------- -void -Table::ScrollTo(BPoint p) -{ - float h = Frame().Height()+1; - if (Parent()) { - BScrollView* scrollView = dynamic_cast(Parent()); - if (scrollView) { - BScrollBar *sb = scrollView->ScrollBar(B_VERTICAL); - float min, max; - sb->GetRange(&min, &max); - if (p.y < (h/2)) p.y = 0; - else if (p.y > max) p.y = max; +void Permissions::Encode(BString* s) { + bool first = true; + s->Truncate(0); + for (int i = 0; i < fNofPermissions; i ++) { + if (!At(i)->IsAllowed()) { + if (first) { + first = false; + } else { + s->Append(" "); + } + s->Append(At(i)->GetPDFName()); } } - inherited::ScrollTo(p); } - // -------------------------------------------------- DocInfoWindow::DocInfoWindow(BMessage *doc_info) : HWindow(BRect(0,0,400,220), "Document Information", B_TITLED_WINDOW_LOOK, @@ -243,18 +86,80 @@ DocInfoWindow::DocInfoWindow(BMessage *doc_info) // ---- Ok, build a default page setup user interface BRect r; BBox *panel; - BButton *button; - float x, y, w, h; - BString setting_value; - + BTabView *tabView; + BString permissions; fDocInfo = doc_info; - // add a *dialog* background + if (DocInfo()->FindString("permissions", &permissions) == B_OK) { + fPermissions.Decode(permissions.String()); + } + r = Bounds(); - panel = new BBox(r, "top_panel", B_FOLLOW_ALL, - B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, - B_PLAIN_BORDER); + tabView = new BTabView(r, "tab_view"); + SetupDocInfoView(CreateTabPanel(tabView, "Information")); + //SetupPasswordView(CreateTabPanel(tabView, "Password")); + //SetupPermissionsView(CreateTabPanel(tabView, "Permissions")); + + AddChild(tabView); + MoveTo(320, 320); + + if (fTable->ChildAt(0)) fTable->ChildAt(0)->MakeFocus(); +} + +BBox* +DocInfoWindow::CreateTabPanel(BTabView* tabView, const char* label) { + BRect r(tabView->Bounds()); + r.bottom -= tabView->TabHeight(); + // create tab panel + BBox* panel = new BBox(r, "top_panel", B_FOLLOW_ALL, + B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, + B_PLAIN_BORDER);; + // add panel to tab + BTab* tab = new BTab(); + tabView->AddTab(panel, tab); + tab->SetLabel(label); + return panel; +} + + +void +DocInfoWindow::SetupButtons(BBox* panel) { + BButton *button; + float x, y, w, h; + BRect r(panel->Bounds()); + + // add a "OK" button, and make it default + button = new BButton(r, NULL, "OK", new BMessage(OK_MSG), + B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); + button->ResizeToPreferred(); + button->GetPreferredSize(&w, &h); + x = r.right - w - 8; + y = r.bottom - h - 8; + button->MoveTo(x, y); + panel->AddChild(button); + + // add a "Cancel button + button = new BButton(r, NULL, "Cancel", new BMessage(CANCEL_MSG), + B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); + button->GetPreferredSize(&w, &h); + button->ResizeToPreferred(); + button->MoveTo(x - w - 8, y); + panel->AddChild(button); + + // add a separator line... + BBox * line = new BBox(BRect(r.left, y - 9, r.right, y - 8), NULL, + B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM ); + panel->AddChild(line); +} + +void +DocInfoWindow::SetupDocInfoView(BBox* panel) { + BButton *button; + float x, y, w, h; + + BRect r(panel->Bounds()); + // add list of keys fKeyList = new BMenu("Delete Key"); BMenuField *menu = new BMenuField(BRect(0, 0, 90, 10), "delete", "", fKeyList); @@ -295,40 +200,49 @@ DocInfoWindow::DocInfoWindow(BMessage *doc_info) add->MoveTo(keys->Frame().right + 5, keys->Frame().top); // fill table - BuildTable(fDocInfo); - - // add a "OK" button, and make it default - button = new BButton(r, NULL, "OK", new BMessage(OK_MSG), - B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); - button->ResizeToPreferred(); - button->GetPreferredSize(&w, &h); - x = r.right - w - 8; - y = r.bottom - h - 8; - button->MoveTo(x, y); - panel->AddChild(button); - - // add a "Cancel button - button = new BButton(r, NULL, "Cancel", new BMessage(CANCEL_MSG), - B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); - button->GetPreferredSize(&w, &h); - button->ResizeToPreferred(); - button->MoveTo(x - w - 8, y); - panel->AddChild(button); - - // add a separator line... - BBox * line = new BBox(BRect(r.left, y - 9, r.right, y - 8), NULL, - B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM ); - panel->AddChild(line); - - // Finally, add our panel to window - AddChild(panel); - - MoveTo(320, 320); - - if (fTable->ChildAt(0)) fTable->ChildAt(0)->MakeFocus(); + BMessage doc_info; + fDocInfo->FindMessage("doc_info", &doc_info); + BuildTable(&doc_info); + SetupButtons(panel); } +BTextControl* +DocInfoWindow::AddPasswordControl(BRect r, BView* panel, const char* name, const char* label) { + BString s; + BTextControl* text; + if (DocInfo()->FindString(name, &s) != B_OK) s = ""; + text = new BTextControl(r, name, label, "", NULL); + text->TextView()->HideTyping(true); + text->TextView()->SetText(s.String()); + panel->AddChild(text); + return text; +} + +// -------------------------------------------------- +void +DocInfoWindow::SetupPasswordView(BBox* panel) { + BRect r(panel->Bounds()); + BRect r1(5, 5, r.Width()-10, 25); + BString label; + + fMasterPassword = AddPasswordControl(r1, panel, "master_password", "Master Password:"); + r1.OffsetBy(0, fMasterPassword->Bounds().Height()); + fUserPassword = AddPasswordControl(r1, panel, "user_password", "User Password:"); + + float w = max_c(panel->StringWidth(fMasterPassword->Label()), panel->StringWidth(fUserPassword->Label())); + fMasterPassword->SetDivider(w); + fUserPassword->SetDivider(w); + + SetupButtons(panel); +} + +void +DocInfoWindow::SetupPermissionsView(BBox* panel) { + + SetupButtons(panel); +} + // -------------------------------------------------- bool DocInfoWindow::QuitRequested() @@ -351,7 +265,14 @@ void DocInfoWindow::MessageReceived(BMessage *msg) { switch (msg->what){ - case OK_MSG: ReadFieldsFromTable(fDocInfo); Quit(); + case OK_MSG: { + BMessage doc_info; + ReadFieldsFromTable(&doc_info); + DocInfo()->ReplaceMessage("doc_info", &doc_info); + ReadPasswords(); + ReadPermissions(); + Quit(); + } break; case CANCEL_MSG: Quit(); @@ -433,7 +354,26 @@ DocInfoWindow::BuildTable(BMessage *docInfo) // -------------------------------------------------- void -DocInfoWindow::ReadFieldsFromTable(BMessage *toDocInfo) +DocInfoWindow::ReadPasswords() +{ + //AddString(DocInfo(), "master_password", fMasterPassword->TextView()->Text()); + //AddString(DocInfo(), "user_password", fUserPassword->TextView()->Text()); +} + +// -------------------------------------------------- +void +DocInfoWindow::ReadPermissions() +{ + BString permissions; + fPermissions.Encode(&permissions); +// AddString(DocInfo(), "permissions", permissions.String()); +} + + + +// -------------------------------------------------- +void +DocInfoWindow::ReadFieldsFromTable(BMessage* doc_info) { BView* child; BMessage m; @@ -443,7 +383,7 @@ DocInfoWindow::ReadFieldsFromTable(BMessage *toDocInfo) m.AddString(t->Label(), t->Text()); } } - *toDocInfo = m; + *doc_info = m; } diff --git a/src/add-ons/print/drivers/pdf/source/DocInfoWindow.h b/src/add-ons/print/drivers/pdf/source/DocInfoWindow.h index ee9af50fce..0f37c6f98a 100644 --- a/src/add-ons/print/drivers/pdf/source/DocInfoWindow.h +++ b/src/add-ons/print/drivers/pdf/source/DocInfoWindow.h @@ -39,8 +39,52 @@ THE SOFTWARE. #include #include #include +#include "InterfaceUtils.h" #include "Utils.h" +class PermissionLabels { +private: + const char* fName; + const char* fPDFName; + +public: + PermissionLabels(const char* name, const char* pdfName) : fName(name), fPDFName(pdfName) { } + // accessors + const char* GetName() const { return fName; } + const char* GetPDFName() const { return fName; } +}; + +class Permission { +private: + const PermissionLabels* fLabels; + bool fAllowed; + +public: + Permission() : fLabels(NULL), fAllowed(true) { } + // accessors + const char* GetName() const { return fLabels->GetName(); } + const char* GetPDFName() const { return fLabels->GetPDFName(); } + bool IsAllowed() const { return fAllowed; } + // setter + void SetLabels(const PermissionLabels* labels) { fLabels = labels; } + void SetAllowed(bool allowed) { fAllowed = allowed; } +}; + +class Permissions { +private: + Permission* fPermissions; + int fNofPermissions; + +public: + Permissions(); + // accessors + Permission* At(int i) { return &fPermissions[i]; } + int Length() const { return fNofPermissions; } + // decode/encode pdflib permission string + void Decode(const char* s); + void Encode(BString* s); +}; + class DocInfoWindow : public HWindow { public: @@ -66,13 +110,26 @@ public: virtual void Quit(); private: - BMessage *fDocInfo; + BMessage *fDocInfo; // owned by parent window BView *fTable; BScrollView *fTableScrollView; BMenu *fKeyList; + BTextControl *fMasterPassword; + BTextControl *fUserPassword; + Permissions fPermissions; + + BMessage* DocInfo() { return fDocInfo; } + BBox* CreateTabPanel(BTabView* tabView, const char* label); + void SetupButtons(BBox* panel); + void SetupDocInfoView(BBox* panel); + BTextControl* AddPasswordControl(BRect r, BView* panel, const char* name, const char* label); + void SetupPasswordView(BBox* panel); + void SetupPermissionsView(BBox* panel); void BuildTable(BMessage *fromDocInfo); - void ReadFieldsFromTable(BMessage *toDocInfo); + void ReadFieldsFromTable(BMessage* doc_info); + void ReadPasswords(); + void ReadPermissions(); void EmptyKeyList(); bool IsValidKey(const char *key); void AddKey(BMessage* msg, bool textControl); diff --git a/src/add-ons/print/drivers/pdf/source/DrawShape.cpp b/src/add-ons/print/drivers/pdf/source/DrawShape.cpp index 103a40a531..cbec9a7211 100644 --- a/src/add-ons/print/drivers/pdf/source/DrawShape.cpp +++ b/src/add-ons/print/drivers/pdf/source/DrawShape.cpp @@ -32,6 +32,7 @@ THE SOFTWARE. #include "PDFLinePathBuilder.h" #include "Log.h" #include "Report.h" +#include "PDFWriter.h" #ifdef CODEWARRIOR #pragma mark [BShape drawing support routines] @@ -147,9 +148,9 @@ DrawShape::Draw() fDrawn = true; if (IsDrawing()) { if (fStroke) - PDF_stroke(Pdf()); + fWriter->StrokeOrClip(); // strokes always else { - PDF_fill(Pdf()); + fWriter->FillOrClip(); // fills always } } else if (TransformPath()) { EndSubPath(); diff --git a/src/add-ons/print/drivers/pdf/source/FontsWindow.cpp b/src/add-ons/print/drivers/pdf/source/FontsWindow.cpp index 434afe6257..603d965177 100644 --- a/src/add-ons/print/drivers/pdf/source/FontsWindow.cpp +++ b/src/add-ons/print/drivers/pdf/source/FontsWindow.cpp @@ -31,35 +31,11 @@ THE SOFTWARE. #include #include +#include "InterfaceUtils.h" #include "FontsWindow.h" #include "Fonts.h" -class DragListView : public BListView -{ -public: - DragListView(BRect frame, const char *name, - list_view_type type = B_SINGLE_SELECTION_LIST, - uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP, - uint32 flags = B_WILL_DRAW | B_NAVIGABLE | B_FRAME_EVENTS); - bool InitiateDrag(BPoint point, int32 index, bool wasSelected); -}; - -DragListView::DragListView(BRect frame, const char *name, - list_view_type type, - uint32 resizingMode, uint32 flags) - : BListView(frame, name, type, resizingMode, flags) -{ -} - -bool DragListView::InitiateDrag(BPoint point, int32 index, bool wasSelected) -{ - BMessage m; - DragMessage(&m, ItemFrame(index), this); - return true; -} - - class CJKFontItem : public BStringItem { font_encoding fEncoding; diff --git a/src/add-ons/print/drivers/pdf/source/InterfaceUtils.cpp b/src/add-ons/print/drivers/pdf/source/InterfaceUtils.cpp new file mode 100644 index 0000000000..5e4297c243 --- /dev/null +++ b/src/add-ons/print/drivers/pdf/source/InterfaceUtils.cpp @@ -0,0 +1,283 @@ +/* + +InterfaceUtils.cpp + +Copyright (c) 2002 OpenBeOS. + +Author: + Michael Pfeiffer + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +*/ + +#include +#include "InterfaceUtils.h" +#include "Utils.h" + +// Implementation of HWindow + +// -------------------------------------------------- +HWindow::HWindow(BRect frame, const char *title, window_type type, uint32 flags, uint32 workspace, uint32 escape_msg) + : BWindow(frame, title, type, flags, workspace) +{ + Init(escape_msg); +} + + +// -------------------------------------------------- +HWindow::HWindow(BRect frame, const char *title, window_look look, window_feel feel, uint32 flags, uint32 workspace, uint32 escape_msg) + : BWindow(frame, title, look, feel, flags, workspace) +{ + Init(escape_msg); +} + + +// -------------------------------------------------- +void +HWindow::Init(uint32 escape_msg) +{ + AddShortcut('i', 0, new BMessage(B_ABOUT_REQUESTED)); + AddCommonFilter(new EscapeMessageFilter(this, escape_msg)); +} + + +// -------------------------------------------------- +void +HWindow::MessageReceived(BMessage* msg) +{ + if (msg->what == B_ABOUT_REQUESTED) { + AboutRequested(); + } else { + inherited::MessageReceived(msg); + } +} + +// -------------------------------------------------- +static const char* +kAbout = +"PDF Writer for BeOS\n" +"© 2001, 2002 OpenBeOS\n" +"\n" +"\tPhilippe Houdoin - Project Leader\n" +"\tSimon Gauvin - GUI Design\n" +"\tMichael Pfeiffer - PDF Generation, Configuration, Interactive Features\n" +"\tCelerick Stephens - Documentation\n" +; + +void +HWindow::AboutRequested() +{ + BAlert *about = new BAlert("About PDF Writer", kAbout, "Cool"); + BTextView *v = about->TextView(); + if (v) { + rgb_color red = {255, 0, 51, 255}; + rgb_color blue = {0, 102, 255, 255}; + + v->SetStylable(true); + char *text = (char*)v->Text(); + char *s = text; + // set all Be in blue and red + while ((s = strstr(s, "Be")) != NULL) { + int32 i = s - text; + v->SetFontAndColor(i, i+1, NULL, 0, &blue); + v->SetFontAndColor(i+1, i+2, NULL, 0, &red); + s += 2; + } + // first text line + s = strchr(text, '\n'); + BFont font; + v->GetFontAndColor(0, &font); + font.SetSize(12); // font.SetFace(B_OUTLINED_FACE); + v->SetFontAndColor(0, s-text+1, &font, B_FONT_SIZE); + }; + about->Go(); +} + + +// Impelementation of TextView + +// -------------------------------------------------- +TextView::TextView(BRect frame, + const char *name, + BRect textRect, + uint32 rmask, + uint32 flags) + : BTextView(frame, name, textRect, rmask, flags) +{ +} + + +// -------------------------------------------------- +TextView::TextView(BRect frame, + const char *name, + BRect textRect, + const BFont *font, const rgb_color *color, + uint32 rmask, + uint32 flags) + : BTextView(frame, name, textRect, font, color, rmask, flags) +{ +} + + +// -------------------------------------------------- +void +TextView::KeyDown(const char *bytes, int32 numBytes) +{ + if (numBytes == 1 && *bytes == B_TAB) { + BView::KeyDown(bytes, numBytes); + return; + } + inherited::KeyDown(bytes, numBytes); +} + + +// -------------------------------------------------- +void +TextView::Draw(BRect update) +{ + inherited::Draw(update); + if (IsFocus()) { + // stroke focus rectangle + SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR)); + StrokeRect(Bounds()); + } +} + + +// -------------------------------------------------- +void +TextView::MakeFocus(bool focus) +{ + Invalidate(); + inherited::MakeFocus(focus); + // notify TextControl + BView* parent = Parent(); // BBox + if (focus && parent) { + parent = parent->Parent(); // TextControl + TextControl* control = dynamic_cast(parent); + if (control) control->FocusSetTo(this); + } +} + + +// Impelementation of TextControl + +// -------------------------------------------------- +TextControl::TextControl(BRect frame, + const char *name, + const char *label, + const char *initial_text, + BMessage *message, + uint32 rmask, + uint32 flags) + : BView(frame, name, rmask, flags) +{ + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + BRect r(0, 0, frame.Width() / 2 -1, frame.Height()); + fLabel = new BStringView(r, "", label); + BRect f(r); + f.OffsetTo(frame.Width() / 2 + 1, 0); + // box around TextView + BBox *box = new BBox(f, "", B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW); + f.OffsetTo(0, 0); + f.InsetBy(1,1); + r.InsetBy(2,2); + fText = new TextView(f, "", r, rmask, flags | B_NAVIGABLE); + fText->SetWordWrap(false); + fText->DisallowChar('\n'); + fText->Insert(initial_text); + AddChild(fLabel); + AddChild(box); + box->AddChild(fText); +} + + +// -------------------------------------------------- +void +TextControl::ConvertToParent(BView* parent, BView* child, BRect &rect) +{ + do { + child->ConvertToParent(&rect); + child = child->Parent(); + } while (child != NULL && child != parent); +} + + +// -------------------------------------------------- +void +TextControl::FocusSetTo(BView *child) +{ + BRect r; + BView* parent = Parent(); // Table + if (parent) { + ConvertToParent(parent, child, r); + parent->ScrollTo(0, r.top); + } +} + + +// Impelementation of Implementation of Table + +// -------------------------------------------------- +Table::Table(BRect frame, const char *name, uint32 rmode, uint32 flags) + : BView(frame, name, rmode, flags) +{ +} + + +// -------------------------------------------------- +void +Table::ScrollTo(BPoint p) +{ + float h = Frame().Height()+1; + if (Parent()) { + BScrollView* scrollView = dynamic_cast(Parent()); + if (scrollView) { + BScrollBar *sb = scrollView->ScrollBar(B_VERTICAL); + float min, max; + sb->GetRange(&min, &max); + if (p.y < (h/2)) p.y = 0; + else if (p.y > max) p.y = max; + } + } + inherited::ScrollTo(p); +} + + +// Impelementation of DragListView + +// -------------------------------------------------- +DragListView::DragListView(BRect frame, const char *name, + list_view_type type, + uint32 resizingMode, uint32 flags) + : BListView(frame, name, type, resizingMode, flags) +{ +} + +// -------------------------------------------------- +bool DragListView::InitiateDrag(BPoint point, int32 index, bool wasSelected) +{ + BMessage m; + DragMessage(&m, ItemFrame(index), this); + return true; +} + + + diff --git a/src/add-ons/print/drivers/pdf/source/InterfaceUtils.h b/src/add-ons/print/drivers/pdf/source/InterfaceUtils.h new file mode 100644 index 0000000000..2b0e3ff4e8 --- /dev/null +++ b/src/add-ons/print/drivers/pdf/source/InterfaceUtils.h @@ -0,0 +1,117 @@ +/* + +InterfaceUtils.cpp + +Copyright (c) 2002 OpenBeOS. + +Author: + Michael Pfeiffer + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +*/ + +#ifndef _INTERFACE_UTILS_H +#define _INTERFACE_UTILS_H + +#include + +// -------------------------------------------------- +class HWindow : public BWindow +{ +protected: + void Init(uint32 escape_msg); + +public: + typedef BWindow inherited; + + HWindow(BRect frame, const char *title, window_type type, uint32 flags, uint32 workspace = B_CURRENT_WORKSPACE, uint32 escape_msg = B_QUIT_REQUESTED); + HWindow(BRect frame, const char *title, window_look look, window_feel feel, uint32 flags, uint32 workspace = B_CURRENT_WORKSPACE, uint32 escape_msg = B_QUIT_REQUESTED); + + virtual void MessageReceived(BMessage* m); + virtual void AboutRequested(); +}; + +// -------------------------------------------------- +class TextView : public BTextView +{ +public: + typedef BTextView inherited; + + TextView(BRect frame, + const char *name, + BRect textRect, + uint32 rmask = B_FOLLOW_LEFT | B_FOLLOW_TOP, + uint32 flags = B_WILL_DRAW | B_NAVIGABLE); + + TextView(BRect frame, + const char *name, + BRect textRect, + const BFont *font, const rgb_color *color, + uint32 rmask = B_FOLLOW_LEFT | B_FOLLOW_TOP, + uint32 flags = B_WILL_DRAW | B_NAVIGABLE); + + void KeyDown(const char *bytes, int32 numBytes); + void MakeFocus(bool focus = true); + void Draw(BRect r); +}; + + +// -------------------------------------------------- +class TextControl : public BView +{ + BStringView *fLabel; + TextView *fText; +public: + TextControl(BRect frame, + const char *name, + const char *label, + const char *initial_text, + BMessage *message, + uint32 rmask = B_FOLLOW_LEFT | B_FOLLOW_TOP, + uint32 flags = B_WILL_DRAW | B_NAVIGABLE); + const char *Label() { return fLabel->Text(); } + const char *Text() { return fText->Text(); } + void MakeFocus(bool focus = true) { fText->MakeFocus(focus); } + void ConvertToParent(BView* parent, BView* child, BRect &rect); + void FocusSetTo(BView* child); +}; + + +// -------------------------------------------------- +class Table : public BView +{ +public: + typedef BView inherited; + + Table(BRect frame, const char *name, uint32 rmode, uint32 flags); + void ScrollTo(BPoint p); +}; + +class DragListView : public BListView +{ +public: + DragListView(BRect frame, const char *name, + list_view_type type = B_SINGLE_SELECTION_LIST, + uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP, + uint32 flags = B_WILL_DRAW | B_NAVIGABLE | B_FRAME_EVENTS); + bool InitiateDrag(BPoint point, int32 index, bool wasSelected); +}; + +#endif diff --git a/src/add-ons/print/drivers/pdf/source/JobSetupWindow.cpp b/src/add-ons/print/drivers/pdf/source/JobSetupWindow.cpp index 34141c742e..b1433aa6fc 100644 --- a/src/add-ons/print/drivers/pdf/source/JobSetupWindow.cpp +++ b/src/add-ons/print/drivers/pdf/source/JobSetupWindow.cpp @@ -37,6 +37,10 @@ THE SOFTWARE. #include "JobSetupWindow.h" #include "DocInfoWindow.h" +static const char* includeKeys[] = { + "doc_info", "master_password", "user_password", "permissions", NULL +}; + // -------------------------------------------------- JobSetupWindow::JobSetupWindow(BMessage *msg, const char * printerName) : HWindow(BRect(0, 0, 320, 160), "Job Setup", B_TITLED_WINDOW_LOOK, @@ -69,14 +73,18 @@ JobSetupWindow::JobSetupWindow(BMessage *msg, const char * printerName) char buffer[80]; // PrinterDriver ensures that property exists - msg->FindInt32("copies", &copies); - msg->FindInt32("first_page", &firstPage); - msg->FindInt32("last_page", &lastPage); - if (B_OK != msg->FindMessage("doc_info", &fDocInfo)) { - fDocInfo.AddString("Author", ""); - fDocInfo.AddString("Subject", ""); - fDocInfo.AddString("Keywords", ""); + fSetupMsg->FindInt32("copies", &copies); + fSetupMsg->FindInt32("first_page", &firstPage); + fSetupMsg->FindInt32("last_page", &lastPage); + BMessage doc_info; + if (B_OK != fSetupMsg->FindMessage("doc_info", &doc_info)) { + // default fields + doc_info.AddString("Author", ""); + doc_info.AddString("Subject", ""); + doc_info.AddString("Keywords", ""); + msg->AddMessage("doc_info", &doc_info); } + AddFields(&fDocInfo, fSetupMsg, NULL, includeKeys); allPages = firstPage == 1 && lastPage == MAX_INT32; @@ -247,11 +255,7 @@ JobSetupWindow::UpdateJobMessage() fSetupMsg->ReplaceInt32("copies", copies); fSetupMsg->ReplaceInt32("first_page", from); fSetupMsg->ReplaceInt32("last_page", to); - if (fSetupMsg->HasMessage("doc_info")) { - fSetupMsg->ReplaceMessage("doc_info", &fDocInfo); - } else { - fSetupMsg->AddMessage("doc_info", &fDocInfo); - } + AddFields(fSetupMsg, &fDocInfo); } @@ -292,6 +296,7 @@ JobSetupWindow::MessageReceived(BMessage *msg) break; case DOC_INFO_MSG: + fDocInfo.PrintToStream(); fflush(stdout); (new DocInfoWindow(&fDocInfo))->Show(); break; @@ -309,9 +314,7 @@ JobSetupWindow::Go() MoveTo(300,300); Show(); acquire_sem(fExitSem); - Lock(); - Quit(); - + if (Lock()) Quit(); return fResult; } diff --git a/src/add-ons/print/drivers/pdf/source/JobSetupWindow.h b/src/add-ons/print/drivers/pdf/source/JobSetupWindow.h index 6ccdc87de8..a32e76f5d2 100644 --- a/src/add-ons/print/drivers/pdf/source/JobSetupWindow.h +++ b/src/add-ons/print/drivers/pdf/source/JobSetupWindow.h @@ -33,6 +33,7 @@ THE SOFTWARE. #define JOBSETUPWINDOW_H #include +#include "InterfaceUtils.h" #include "Utils.h" class JobSetupWindow : public HWindow diff --git a/src/add-ons/print/drivers/pdf/source/PDFLinePathBuilder.h b/src/add-ons/print/drivers/pdf/source/PDFLinePathBuilder.h index 2be1e67bea..eb70d5f51f 100644 --- a/src/add-ons/print/drivers/pdf/source/PDFLinePathBuilder.h +++ b/src/add-ons/print/drivers/pdf/source/PDFLinePathBuilder.h @@ -48,10 +48,6 @@ protected: void ClosePath(void); public: - cap_mode LineCapMode() const { return fWriter->fState->capMode; } - join_mode LineJoinMode() const { return fWriter->fState->joinMode; } - float LineMiterLimit() const { return fWriter->fState->miterLimit; } - PDFLinePathBuilder(SubPath *subPath, PDFWriter *writer); }; diff --git a/src/add-ons/print/drivers/pdf/source/PDFText.cpp b/src/add-ons/print/drivers/pdf/source/PDFText.cpp index 600d37e771..d16931f922 100644 --- a/src/add-ons/print/drivers/pdf/source/PDFText.cpp +++ b/src/add-ons/print/drivers/pdf/source/PDFText.cpp @@ -490,6 +490,7 @@ PDFWriter::DrawString(char *string, float escapement_nospace, float escapement_s BPoint start(fState->penX, fState->penY); + BeginTransparency(); // If !MakesPDF() all the effort below just for the bounding box! // draw each character const char *c = utf8.String(); @@ -520,6 +521,7 @@ PDFWriter::DrawString(char *string, float escapement_nospace, float escapement_s // next character c += s; u += 2; } + EndTransparency(); // text line processing (for non rotated text only!) BPoint end(fState->penX, fState->penY); @@ -539,6 +541,9 @@ PDFWriter::DrawString(char *string, float escapement_nospace, float escapement_s &bounds, &font, pdfSystem()); fTextLine.Add(segment); + + if (IsDrawing()) { + } } diff --git a/src/add-ons/print/drivers/pdf/source/PDFWriter.cpp b/src/add-ons/print/drivers/pdf/source/PDFWriter.cpp index e05333f149..24d11e5e1a 100644 --- a/src/add-ons/print/drivers/pdf/source/PDFWriter.cpp +++ b/src/add-ons/print/drivers/pdf/source/PDFWriter.cpp @@ -149,12 +149,16 @@ PDFWriter::PrintPage(int32 pageNumber, int32 pageCount) r = picRegion->Frame(); delete picRegion; + PDF_TRY(fPdf) { BeginPage(paperRect, printRect); for (i = 0; i < pictureCount; i++) { Iterate(pictures[i]); delete pictures[i]; } EndPage(); + } PDF_CATCH(fPdf) { + REPORT(kError, 0, PDF_get_errmsg(fPdf)); + } free(pictures); free(picRects); @@ -254,15 +258,48 @@ PDFWriter::InitWriter() char buffer[512]; BString s; + fState = NULL; + fStateDepth = 0; + + // pdflib scope: object + const char* license_key; + if (JobMsg()->FindString("pdflib_license_key", &license_key) == B_OK && + license_key[0] != 0) { + REPORT(kDebug, 0, "license key found %s!", license_key); + PDF_set_parameter(fPdf, "license", license_key); + } + + fPDFVersion = kPDF13; const char * compatibility; if (JobMsg()->FindString("pdf_compatibility", &compatibility) == B_OK) { PDF_set_parameter(fPdf, "compatibility", compatibility); + if (strcmp(compatibility, "1.3") == 0) fPDFVersion = kPDF13; + else if (strcmp(compatibility, "1.4") == 0) fPDFVersion = kPDF14; + else if (strcmp(compatibility, "1.5") == 0) fPDFVersion = kPDF15; + } + + // set user/master password + BString master_password, user_password; + if (JobMsg()->FindString("master_password", &master_password) == B_OK && + JobMsg()->FindString("user_password", &user_password) == B_OK && + master_password.Length() > 0 && user_password.Length() > 0) { + PDF_set_parameter(fPdf, "masterpassword", master_password.String()); + PDF_set_parameter(fPdf, "userpassword", user_password.String()); + } + + // set permissions + BString permissions; + if (JobMsg()->FindString("permissions", &permissions) == B_OK && + permissions.Length() > 0) { + PDF_set_parameter(fPdf, "permissions", permissions.String()); } REPORT(kDebug, 0, ">>>> PDF_open_mem"); PDF_open_mem(fPdf, _WriteData); // use callback to stream PDF document data to printer transport + + // pdflib scope: - PDF_set_parameter(fPdf, "flush", "heavy"); + PDF_set_parameter(fPdf, "flush", "content"); // set document info BMessage doc; @@ -370,9 +407,6 @@ PDFWriter::InitWriter() } } - fState = NULL; - fStateDepth = 0; - return B_OK; } @@ -469,7 +503,7 @@ PDFWriter::BeginPage(BRect paperRect, BRect printRect) // -------------------------------------------------- status_t PDFWriter::EndPage() -{ +{ fTextLine.Flush(); if (fCreateBookmarks) fBookmark->CreateBookmarks(); @@ -529,7 +563,6 @@ PDFWriter::PopInternalState() State* s = fState; fStateDepth --; fState = fState->prev; delete s; -// LOG((fLog, "height = %f x0 = %f y0 = %f", pdfSystem->Height(), pdfSystem->Origin().x, pdfSystem.Origin().y)); return true; } else { REPORT(kDebug, fPage, "State stack underflow!"); @@ -538,11 +571,94 @@ PDFWriter::PopInternalState() } +// -------------------------------------------------- +PDFWriter::Transparency* +PDFWriter::FindTransparency(uint8 alpha) +{ + const int n = fTransparencyCache.CountItems(); + for (int i = 0; i < n; i ++) { + Transparency* t = fTransparencyCache.ItemAt(i); + if (t->Matches(alpha)) { + // return handle for existing gstate + return t; + } + } + + // create new handle for gstate + char trans[256]; + float a = (float)alpha/255.0; + sprintf(trans, "opacitystroke=%f opacityfill=%f", a, a); + + int handle = -1; + PDF_TRY(fPdf) { + handle = PDF_create_gstate(fPdf, trans); + } PDF_CATCH(fPdf) { + REPORT(kError, 0, PDF_get_errmsg(fPdf)); + } + REPORT(kDebug, fPage, trans); + + if (handle >= 0) { + // store in cache + Transparency* t = new Transparency(alpha, handle); + fTransparencyCache.AddItem(t); + return t; + } + + return NULL; +} + +// -------------------------------------------------- +void +PDFWriter::BeginTransparency() +{ + if (!SupportsOpacity() || !MakesPDF() || !IsDrawing()) return; + REPORT(kDebug, fPage, ">>> BeginTransparency"); + REPORT(kDebug, fPage, "current_color(%d, %d, %d, %d)", fState->currentColor.red, fState->currentColor.green, fState->currentColor.blue, fState->currentColor.alpha); + REPORT(kDebug, fPage, "drawing_mode %d alpha %d", (int)fState->drawingMode, (int)fState->currentColor.alpha); + + Transparency* t = NULL; + + uint8 alpha = fState->currentColor.alpha; + if (fState->drawingMode == B_OP_ALPHA && alpha < 255) { + PDF_save(fPdf); + t = FindTransparency(alpha); + if (t != NULL) { + PDF_TRY(fPdf) { + PDF_set_gstate(fPdf, t->Handle()); + } PDF_CATCH(fPdf) { + REPORT(kError, 0, PDF_get_errmsg(fPdf)); + } + } + } + // if transparency is not set then push NULL to transparency stack + fTransparencyStack.AddItem(t); +} + +// -------------------------------------------------- +void +PDFWriter::EndTransparency() +{ + if (!SupportsOpacity() || !MakesPDF() || !IsDrawing()) return; + REPORT(kDebug, fPage, "<<< EndTransparency"); + int lastItem = fTransparencyStack.CountItems()-1; + Transparency* t = fTransparencyStack.RemoveItem(lastItem); + + if (t != NULL) { + PDF_restore(fPdf); + } +} + // -------------------------------------------------- void PDFWriter::SetColor(rgb_color color) { - if (!MakesPDF()) return; + if (!MakesPDF()) { + // create PDFlib gstate handles + if (SupportsOpacity() && fState->currentColor.alpha != color.alpha && color.alpha < 255) { + FindTransparency(color.alpha); + } + return; + } if (fState->currentColor.red != color.red || fState->currentColor.blue != color.blue || fState->currentColor.green != color.green || @@ -551,7 +667,8 @@ PDFWriter::SetColor(rgb_color color) float red = color.red / 255.0; float green = color.green / 255.0; float blue = color.blue / 255.0; - PDF_setcolor(fPdf, "both", "rgb", red, green, blue, 0.0); + PDF_setcolor(fPdf, "both", "rgb", red, green, blue, 0.0); + REPORT(kDebug, fPage, "set_color(%f, %f, %f, %f)", red, green, blue, color.alpha/255.0); } } @@ -815,7 +932,7 @@ PDFWriter::BytesPerPixel(int32 pixelFormat) // -------------------------------------------------- bool -PDFWriter::NeedsAlphaCheck(int32 pixelFormat) +PDFWriter::HasAlphaChannel(int32 pixelFormat) { switch (pixelFormat) { case B_RGB32: // fall through @@ -835,6 +952,20 @@ PDFWriter::NeedsAlphaCheck(int32 pixelFormat) } } +// -------------------------------------------------- +bool +PDFWriter::NeedsBPC1Mask(int32 pixelFormat) { + switch (pixelFormat) { +// case B_RGB32: // fall through +// case B_RGB32_BIG: // fall through + case B_RGB15: // fall through + case B_RGB15_BIG: // fall through + case B_RGBA15: // fall through + case B_RGBA15_BIG: // fall through + case B_CMAP8: return true; + default: return false; + }; +} // -------------------------------------------------- bool @@ -978,7 +1109,7 @@ PDFWriter::CreateMask(BRect src, int32 bytesPerRow, int32 pixelFormat, int32 fla int32 maskWidth; uint8 shift; bool alpha; - int32 bpp = 4; + int32 bpp; bpp = BytesPerPixel(pixelFormat); if (bpp < 0) @@ -987,9 +1118,6 @@ PDFWriter::CreateMask(BRect src, int32 bytesPerRow, int32 pixelFormat, int32 fla int32 width = src.IntegerWidth() + 1; int32 height = src.IntegerHeight() + 1; - if (!NeedsAlphaCheck(pixelFormat)) - return NULL; - // Image Mask inRow = (uint8 *) data; inRow += bytesPerRow * (int) src.top + bpp * (int) src.left; @@ -1051,6 +1179,93 @@ PDFWriter::CreateMask(BRect src, int32 bytesPerRow, int32 pixelFormat, int32 fla } +// -------------------------------------------------- +uint8 +PDFWriter::AlphaFromRGBA32(uint8* in) +{ + return in[2]; +} + + +// -------------------------------------------------- +uint8 +PDFWriter::AlphaFromRGBA32_BIG(uint8* in) +{ + return in[0]; +} + + +// -------------------------------------------------- +void * +PDFWriter::CreateSoftMask(BRect src, int32 bytesPerRow, int32 pixelFormat, int32 flags, void *data) +{ + uint8 *in; + uint8 *inRow; + int32 x, y; + + uint8 *mask; + uint8 *maskRow; + uint8 *out; + bool alpha; + int32 bpp; + + return NULL; + + bpp = BytesPerPixel(pixelFormat); + if (bpp < 0) + return NULL; + + int32 width = src.IntegerWidth() + 1; + int32 height = src.IntegerHeight() + 1; + + // Image Mask + inRow = (uint8 *) data; + inRow += bytesPerRow * (int) src.top + bpp * (int) src.left; + + // soft mask with 8 bits per component + maskRow = mask = new uint8[width * height]; + memset(mask, 0, width * height); + alpha = false; + + for (y = height; y > 0; y--) { + in = inRow; + out = maskRow; + + uint8 a; + + for (x = width; x > 0; x-- ) { + // For each pixel + switch (pixelFormat) { + case B_RGB32: // fall through + case B_RGBA32: a = AlphaFromRGBA32(in); break; + case B_RGB32_BIG: // fall through + case B_RGBA32_BIG: a = AlphaFromRGBA32_BIG(in); break; + default: a = 255; // should not reach here + REPORT(kDebug, fPage, "CreateSoftMask: non transparentable pixelFormat"); + } + + *out = a; + if (a != 255) { + alpha = true; + } + // next pixel + out ++; + in += bpp; + } + + // next row + inRow += bytesPerRow; + maskRow += width; + } + + if (!alpha) { + delete []mask; + mask = NULL; + } + return mask; +} + + // -------------------------------------------------- void PDFWriter::ConvertFromRGB32(uint8* in, uint8 *out) @@ -1368,20 +1583,36 @@ PDFWriter::StoreTranslatorBitmap(BBitmap *bitmap, const char *filename, uint32 t // -------------------------------------------------- bool -PDFWriter::GetImages(BRect src, int32 width, int32 height, int32 bytesPerRow, int32 pixelFormat, +PDFWriter::GetImages(BRect src, int32 /*width*/, int32 /*height*/, int32 bytesPerRow, int32 pixelFormat, int32 flags, void *data, int* maskId, int* image) { void *mask = NULL; *maskId = -1; - mask = CreateMask(src, bytesPerRow, pixelFormat, flags, data); - + int32 width = src.IntegerWidth() + 1; + int32 height = src.IntegerHeight() + 1; + int length; + int bpc; + + + + if (HasAlphaChannel(pixelFormat)) { + if (NeedsBPC1Mask(pixelFormat) || !SupportsSoftMask()) { + int32 w = (width+7)/8; + length = w * height; + bpc = 1; + mask = CreateMask(src, bytesPerRow, pixelFormat, flags, data); + REPORT(kDebug, fPage, "Mask created mask = %p", mask); + } else { + length = width * height; + bpc = 8; + mask = CreateSoftMask(src, bytesPerRow, pixelFormat, flags, data); + REPORT(kDebug, fPage, "SoftMask created mask = %p", mask); + } + } + if (mask) { - int32 width = src.IntegerWidth() + 1; - int32 height = src.IntegerHeight() + 1; - int32 w = (width+7)/8; - int32 h = height; - *maskId = PDF_open_image(fPdf, "raw", "memory", (const char *) mask, w*h, width, height, 1, 1, "mask"); + *maskId = PDF_open_image(fPdf, "raw", "memory", (const char *) mask, length, width, height, 1, bpc, "mask"); delete []mask; } @@ -1449,9 +1680,11 @@ PDFWriter::StrokeLine(BPoint start, BPoint end) shape.LineTo(end); StrokeShape(&shape); } else { + BeginTransparency(); PDF_moveto(fPdf, tx(start.x), ty(start.y)); PDF_lineto(fPdf, tx(end.x), ty(end.y)); StrokeOrClip(); + EndTransparency(); } } @@ -1474,8 +1707,10 @@ PDFWriter::StrokeRect(BRect rect) shape.Close(); StrokeShape(&shape); } else { + BeginTransparency(); PDF_rect(fPdf, tx(rect.left), ty(rect.bottom), scale(rect.Width()), scale(rect.Height())); StrokeOrClip(); + EndTransparency(); } } @@ -1489,8 +1724,10 @@ PDFWriter::FillRect(BRect rect) SetColor(); if (!MakesPDF()) return; + BeginTransparency(); PDF_rect(fPdf, tx(rect.left), ty(rect.bottom), scale(rect.Width()), scale(rect.Height())); FillOrClip(); + EndTransparency(); } @@ -1502,11 +1739,15 @@ void PDFWriter::PaintRoundRect(BRect rect, BPoint radii, bool stroke) { SetColor(); if (!MakesPDF()) return; - + BPoint center; float sx = radii.x; float sy = radii.y; + + char str[256]; + sprintf(str, "PaintRoundRect sx %f sy %f", sx, sy); + REPORT(kDebug, fPage, str); float ax = sx; float bx = 0.5555555555555 * sx; @@ -1514,40 +1755,40 @@ PDFWriter::PaintRoundRect(BRect rect, BPoint radii, bool stroke) { float by = 0.5555555555555 * sy; center.x = rect.left + sx; - center.y = rect.top - sy; + center.y = rect.top + sy; BShape shape; shape.MoveTo(BPoint(center.x - ax, center.y)); BPoint a[3] = { - BPoint(center.x - ax, center.y + by), - BPoint(center.x - bx, center.y + ay), - BPoint(center.x , center.y + ay)}; + BPoint(center.x - ax, center.y - by), + BPoint(center.x - bx, center.y - ay), + BPoint(center.x , center.y - ay)}; shape.BezierTo(a); center.x = rect.right - sx; - shape.LineTo(BPoint(center.x, center.y + ay)); + shape.LineTo(BPoint(center.x, center.y - ay)); BPoint b[3] = { - BPoint(center.x + bx, center.y + ay), - BPoint(center.x + ax, center.y + by), + BPoint(center.x + bx, center.y - ay), + BPoint(center.x + ax, center.y - by), BPoint(center.x + ax, center.y)}; shape.BezierTo(b); - center.y = rect.bottom + sy; + center.y = rect.bottom - sy; shape.LineTo(BPoint(center.x + sx, center.y)); BPoint c[3] = { - BPoint(center.x + ax, center.y - by), - BPoint(center.x + bx, center.y - ay), - BPoint(center.x , center.y - ay)}; + BPoint(center.x + ax, center.y + by), + BPoint(center.x + bx, center.y + ay), + BPoint(center.x , center.y + ay)}; shape.BezierTo(c); center.x = rect.left + sx; - shape.LineTo(BPoint(center.x, center.y - ay)); + shape.LineTo(BPoint(center.x, center.y + ay)); BPoint d[3] = { - BPoint(center.x - bx, center.y - ay), - BPoint(center.x - ax, center.y - by), + BPoint(center.x - bx, center.y + ay), + BPoint(center.x - ax, center.y + by), BPoint(center.x - ax, center.y)}; shape.BezierTo(d); @@ -1584,7 +1825,6 @@ PDFWriter::StrokeBezier(BPoint *control) REPORT(kDebug, fPage, "StrokeBezier"); SetColor(); if (!MakesPDF()) return; - BShape shape; shape.MoveTo(control[0]); shape.BezierTo(&control[1]); @@ -1744,6 +1984,7 @@ PDFWriter::StrokePolygon(int32 numPoints, BPoint *points, bool isClosed) shape.Close(); StrokeShape(&shape); } else { + BeginTransparency(); for ( i = 0; i < numPoints; i++, points++ ) { REPORT(kDebug, fPage, " [%f, %f]", points->x, points->y); if (i != 0) { @@ -1757,6 +1998,7 @@ PDFWriter::StrokePolygon(int32 numPoints, BPoint *points, bool isClosed) if (isClosed) PDF_lineto(fPdf, x0, y0); StrokeOrClip(); + EndTransparency(); } } @@ -1773,6 +2015,7 @@ PDFWriter::FillPolygon(int32 numPoints, BPoint *points, bool isClosed) SetColor(); if (!MakesPDF()) return; + BeginTransparency(); for ( i = 0; i < numPoints; i++, points++ ) { REPORT(kDebug, fPage, " [%f, %f]", points->x, points->y); if (i != 0) { @@ -1783,6 +2026,7 @@ PDFWriter::FillPolygon(int32 numPoints, BPoint *points, bool isClosed) } PDF_closepath(fPdf); FillOrClip(); + EndTransparency(); } @@ -1799,8 +2043,10 @@ void PDFWriter::StrokeShape(BShape *shape) REPORT(kDebug, fPage, "StrokeShape"); SetColor(); if (!MakesPDF()) return; + BeginTransparency(); DrawShape iterator(this, true); iterator.Iterate(shape); + EndTransparency(); } @@ -1810,8 +2056,10 @@ void PDFWriter::FillShape(BShape *shape) REPORT(kDebug, fPage, "FillShape"); SetColor(); if (!MakesPDF()) return; + BeginTransparency(); DrawShape iterator(this, false); iterator.Iterate(shape); + EndTransparency(); } @@ -1827,8 +2075,9 @@ PDFWriter::ClipToPicture(BPicture *picture, BPoint point, bool clip_to_inverse_p } if (fMode == kDrawingMode) { const bool set_origin = point.x != 0 || point.y != 0; + PushInternalState(); if (set_origin) { - PushInternalState(); SetOrigin(point); PushInternalState(); + SetOrigin(point); PushInternalState(); } fMode = kClippingMode; @@ -1839,9 +2088,10 @@ PDFWriter::ClipToPicture(BPicture *picture, BPoint point, bool clip_to_inverse_p PDF_clip(fPdf); if (set_origin) { - PopInternalState(); PopInternalState(); + PopInternalState(); } - + PopInternalState(); + REPORT(kDebug, fPage, "Returning from ClipToPicture"); } else { REPORT(kError, fPage, "Nested call of ClipToPicture not implemented yet!"); @@ -1860,6 +2110,7 @@ PDFWriter::DrawPixels(BRect src, BRect dest, int32 width, int32 height, int32 by dest.left, dest.top, dest.right, dest.bottom, \ width, height, bytesPerRow, pixelFormat, flags, data); + SetColor(); if (!MakesPDF()) return; if (IsClipping()) { @@ -1883,6 +2134,13 @@ PDFWriter::DrawPixels(BRect src, BRect dest, int32 width, int32 height, int32 by PDF_scale(fPdf, scaleX, scaleY); } + // This seems to work with Gobe Productive, why? + // Can use Begin/EndTransparency if the alpha value for each pixel + // is the same. + // Otherwise we need "SoftMasks". Don't know if PDFlib 5.x already + // supports them. + BeginTransparency(); + float x = tx(dest.left) / scaleX; float y = ty(dest.bottom) / scaleY; @@ -1893,6 +2151,9 @@ PDFWriter::DrawPixels(BRect src, BRect dest, int32 width, int32 height, int32 by REPORT(kError, fPage, "PDF_open_image_file failed!"); if (maskId != -1) PDF_close_image(fPdf, maskId); + + EndTransparency(); + if (needs_scaling) PDF_restore(fPdf); } @@ -2071,6 +2332,8 @@ PDFWriter::SetPenSize(float size) void PDFWriter::SetForeColor(rgb_color color) { + //if (IsClipping()) return; // ignore + float red, green, blue; red = color.red / 255.0; @@ -2089,6 +2352,8 @@ PDFWriter::SetForeColor(rgb_color color) void PDFWriter::SetBackColor(rgb_color color) { + //if (IsClipping()) return; // ignore + float red, green, blue; red = color.red / 255.0; diff --git a/src/add-ons/print/drivers/pdf/source/PDFWriter.h b/src/add-ons/print/drivers/pdf/source/PDFWriter.h index 780488f2fa..945d134a93 100644 --- a/src/add-ons/print/drivers/pdf/source/PDFWriter.h +++ b/src/add-ons/print/drivers/pdf/source/PDFWriter.h @@ -93,7 +93,8 @@ class PDFWriter : public PrinterDriver, public PictureIterator // Image support int32 BytesPerPixel(int32 pixelFormat); - bool NeedsAlphaCheck(int32 pixelFormat); + bool HasAlphaChannel(int32 pixelFormat); + bool NeedsBPC1Mask(int32 pixelFormat); inline bool IsTransparentRGB32(uint8* in); inline bool IsTransparentRGBA32(uint8* in); @@ -111,6 +112,9 @@ class PDFWriter : public PrinterDriver, public PictureIterator //inline bool IsTransparentGRAY8(uint8* in); //inline bool IsTransparentGRAY1(uint8* in); + inline uint8 AlphaFromRGBA32(uint8* in); + inline uint8 AlphaFromRGBA32_BIG(uint8* in); + inline void ConvertFromRGB32(uint8* in, uint8* out); inline void ConvertFromRGB32_BIG(uint8* in, uint8* out); inline void ConvertFromRGBA32(uint8* in, uint8* out); @@ -128,6 +132,7 @@ class PDFWriter : public PrinterDriver, public PictureIterator inline void ConvertFromGRAY1(uint8* in, uint8* out, int8 bit); void *CreateMask(BRect src, int32 bytesPerRow, int32 pixelFormat, int32 flags, void *data); + void *CreateSoftMask(BRect src, int32 bytesPerRow, int32 pixelFormat, int32 flags, void *data); BBitmap *ConvertBitmap(BRect src, int32 bytesPerRow, int32 pixelFormat, int32 flags, void *data); bool GetImages(BRect src, int32 width, int32 height, int32 bytesPerRow, int32 pixelFormat, int32 flags, void *data, int* mask, int* image); @@ -194,6 +199,12 @@ class PDFWriter : public PrinterDriver, public PictureIterator private: + enum PDFVersion { + kPDF13, + kPDF14, + kPDF15 + }; + class State { public: @@ -271,7 +282,25 @@ class PDFWriter : public PrinterDriver, public PictureIterator return IsSame(pat, p) && IsSame(lowColor, low) && IsSame(highColor, high); }; }; + + class Transparency + { + uint8 alpha; + int handle; + public: + Transparency(uint8 alpha, int handle) + : alpha(alpha) + , handle(handle) + {}; + + inline bool Matches(uint8 alpha) const { + return this->alpha == alpha; + }; + + inline int Handle() const { return handle; } + }; + PDFVersion fPDFVersion; FILE *fLog; PDF *fPdf; int32 fPage; @@ -279,6 +308,8 @@ class PDFWriter : public PrinterDriver, public PictureIterator int32 fStateDepth; TList fFontCache; TList fPatterns; + TList fTransparencyCache; + TList fTransparencyStack; int64 fEmbedMaxFontSize; BScreen *fScreen; Fonts *fFonts; @@ -315,16 +346,25 @@ class PDFWriter : public PrinterDriver, public PictureIterator inline bool IsDrawing() const { return fMode == kDrawingMode; } inline bool IsClipping() const { return fMode == kClippingMode; } + // PDF features depending on PDF version: + inline bool SupportsSoftMask() const { return fPDFVersion >= kPDF14; } + inline bool SupportsOpacity() const { return fPDFVersion >= kPDF14; } + inline float PenSize() const { return fState->penSize; } inline cap_mode LineCapMode() const { return fState->capMode; } inline join_mode LineJoinMode() const { return fState->joinMode; } inline float LineMiterLimit() const { return fState->miterLimit; } - + bool StoreTranslatorBitmap(BBitmap *bitmap, const char *filename, uint32 type); void GetFontName(BFont *font, char *fontname, bool &embed, font_encoding encoding); int FindFont(char *fontname, bool embed, font_encoding encoding); + // alpha transparency + Transparency* FindTransparency(uint8 alpha); + void BeginTransparency(); + void EndTransparency(); + void PushInternalState(); bool PopInternalState(); diff --git a/src/add-ons/print/drivers/pdf/source/PageSetupWindow.cpp b/src/add-ons/print/drivers/pdf/source/PageSetupWindow.cpp index d9fb2e2fad..0d0f9358f6 100644 --- a/src/add-ons/print/drivers/pdf/source/PageSetupWindow.cpp +++ b/src/add-ons/print/drivers/pdf/source/PageSetupWindow.cpp @@ -77,7 +77,8 @@ static struct {NULL, 0} }; -static const char *pdf_compatibility[] = {"1.2", "1.3", "1.4", NULL}; +// PDFLib 5.x does not support PDF 1.2 anymore! +static const char *pdf_compatibility[] = {"1.3", "1.4", NULL}; /** * Constuctor @@ -437,6 +438,15 @@ PageSetupWindow::UpdateSetupMessage() BString s; int32 i; + + if (fAdvancedSettings.FindString("pdflib_license_key", &s) == B_OK) { + if (fSetupMsg->HasString("pdflib_license_key")) { + fSetupMsg->ReplaceString("pdflib_license_key", s.String()); + } else { + fSetupMsg->AddString("pdflib_license_key", s.String()); + } + } + if (fAdvancedSettings.FindBool("create_web_links", &b) == B_OK) { if (fSetupMsg->HasBool("create_web_links")) { fSetupMsg->ReplaceBool("create_web_links", b); @@ -493,7 +503,7 @@ PageSetupWindow::UpdateSetupMessage() } } - // save the settings to be new defaults + // save the settings to the new defaults PrinterSettings *ps = new PrinterSettings(fPrinterDirName.String()); if (ps->InitCheck() == B_OK) { ps->WriteSettings(fSetupMsg); diff --git a/src/add-ons/print/drivers/pdf/source/PageSetupWindow.h b/src/add-ons/print/drivers/pdf/source/PageSetupWindow.h index 9038444560..98e4fe7c59 100644 --- a/src/add-ons/print/drivers/pdf/source/PageSetupWindow.h +++ b/src/add-ons/print/drivers/pdf/source/PageSetupWindow.h @@ -39,6 +39,7 @@ THE SOFTWARE. #include #include #include +#include "InterfaceUtils.h" #include "Utils.h" #include "Fonts.h" diff --git a/src/add-ons/print/drivers/pdf/source/PrinterSettings.cpp b/src/add-ons/print/drivers/pdf/source/PrinterSettings.cpp index de03612468..b5a51932ee 100644 --- a/src/add-ons/print/drivers/pdf/source/PrinterSettings.cpp +++ b/src/add-ons/print/drivers/pdf/source/PrinterSettings.cpp @@ -157,12 +157,13 @@ status_t PrinterSettings::GetDefaults(BMessage *msg) { // check to see if there is a pdf_printer_settings file - PrinterPrefs *prefs = new PrinterPrefs(); - BMessage *settings = new BMessage(); - settings->what = 'okok'; - if (prefs->LoadSettings(settings) == B_OK) { + PrinterPrefs prefs; + BMessage settings; + settings.what = 'okok'; + + if (prefs.LoadSettings(&settings) == B_OK && Validate(&settings) == B_OK) { // yes, copy the settings into message - *msg = *settings; + *msg = settings; } else { // set default value if property not set msg->AddInt64("xres", XRES); @@ -181,14 +182,15 @@ PrinterSettings::GetDefaults(BMessage *msg) msg->AddBool("create_xrefs", CREATE_XREFS); msg->AddString("xrefs_file", XREFS_FILE); msg->AddInt32("close_option", CLOSE_OPTION); + msg->AddString("pdflib_license_key", PDFLIB_LICENSE_KEY); + msg->AddString("master_password", MASTER_PASSWORD); + msg->AddString("user_password", USER_PASSWORD); + msg->AddString("permissions", PERMISSIONS); // create pdf_printer_settings file - prefs->SaveSettings(msg); + prefs.SaveSettings(msg); } - delete prefs; - delete settings; - return B_OK; } @@ -259,6 +261,18 @@ PrinterSettings::Validate(const BMessage *msg) if (msg->FindInt32("close_option", &i32) != B_OK) { return B_ERROR; } + if (msg->FindString("pdflib_license_key", &s) != B_OK) { + return B_ERROR; + } + if (msg->FindString("user_password", &s) != B_OK) { + return B_ERROR; + } + if (msg->FindString("master_password", &s) != B_OK) { + return B_ERROR; + } + if (msg->FindString("permissions", &s) != B_OK) { + return B_ERROR; + } // message ok return B_OK; } diff --git a/src/add-ons/print/drivers/pdf/source/PrinterSettings.h b/src/add-ons/print/drivers/pdf/source/PrinterSettings.h index aed0a606cc..13bcef2e7d 100644 --- a/src/add-ons/print/drivers/pdf/source/PrinterSettings.h +++ b/src/add-ons/print/drivers/pdf/source/PrinterSettings.h @@ -57,6 +57,10 @@ const char BOOKMARK_DEFINITION_FILE[] = ""; const bool CREATE_XREFS = false; const char XREFS_FILE[] = ""; const int32 CLOSE_OPTION = 0; +const char PDFLIB_LICENSE_KEY[] = ""; +const char USER_PASSWORD[] = ""; // none if empty +const char MASTER_PASSWORD[] = ""; // none if empty +const char PERMISSIONS[] = ""; // all is allowed /** * Class diff --git a/src/add-ons/print/drivers/pdf/source/PrinterSetupWindow.h b/src/add-ons/print/drivers/pdf/source/PrinterSetupWindow.h index da61aa269d..e3f73f6a79 100644 --- a/src/add-ons/print/drivers/pdf/source/PrinterSetupWindow.h +++ b/src/add-ons/print/drivers/pdf/source/PrinterSetupWindow.h @@ -33,6 +33,7 @@ THE SOFTWARE. #define PRINTERSETUPWINDOW_H #include +#include "InterfaceUtils.h" #include "Utils.h" class PrinterSetupWindow : public HWindow diff --git a/src/add-ons/print/drivers/pdf/source/Report.cpp b/src/add-ons/print/drivers/pdf/source/Report.cpp index 4a490e58ef..46111d8ca4 100644 --- a/src/add-ons/print/drivers/pdf/source/Report.cpp +++ b/src/add-ons/print/drivers/pdf/source/Report.cpp @@ -31,6 +31,8 @@ THE SOFTWARE. #include #include +#define LOGGING 0 + Report* Report::fInstance = NULL; diff --git a/src/add-ons/print/drivers/pdf/source/StatusWindow.h b/src/add-ons/print/drivers/pdf/source/StatusWindow.h index fba2160b5f..76bacfafff 100644 --- a/src/add-ons/print/drivers/pdf/source/StatusWindow.h +++ b/src/add-ons/print/drivers/pdf/source/StatusWindow.h @@ -36,6 +36,7 @@ THE SOFTWARE. //class PrinterDriver; #include "PrinterDriver.h" +#include "InterfaceUtils.h" #include "Utils.h" class StatusWindow : public HWindow diff --git a/src/add-ons/print/drivers/pdf/source/Utils.cpp b/src/add-ons/print/drivers/pdf/source/Utils.cpp index 734314365f..780193d6d9 100644 --- a/src/add-ons/print/drivers/pdf/source/Utils.cpp +++ b/src/add-ons/print/drivers/pdf/source/Utils.cpp @@ -30,10 +30,6 @@ THE SOFTWARE. */ #include "Utils.h" -#include -#include -#include -#include // -------------------------------------------------- EscapeMessageFilter::EscapeMessageFilter(BWindow *window, int32 what) @@ -57,82 +53,52 @@ EscapeMessageFilter::Filter(BMessage *msg, BHandler **target) return B_DISPATCH_MESSAGE; } +// -------------------------------------------------- +// copied from BeUtils.cpp +static bool InList(const char* list[], const char* name) { + for (int i = 0; list[i] != NULL; i ++) { + if (strcmp(list[i], name) == 0) return true; + } + return false; +} + +#include // -------------------------------------------------- -HWindow::HWindow(BRect frame, const char *title, window_type type, uint32 flags, uint32 workspace, uint32 escape_msg) - : BWindow(frame, title, type, flags, workspace) -{ - Init(escape_msg); -} - - -// -------------------------------------------------- -HWindow::HWindow(BRect frame, const char *title, window_look look, window_feel feel, uint32 flags, uint32 workspace, uint32 escape_msg) - : BWindow(frame, title, look, feel, flags, workspace) -{ - Init(escape_msg); -} - - -// -------------------------------------------------- -void -HWindow::Init(uint32 escape_msg) -{ - AddShortcut('i', 0, new BMessage(B_ABOUT_REQUESTED)); - AddCommonFilter(new EscapeMessageFilter(this, escape_msg)); -} - - -// -------------------------------------------------- -void -HWindow::MessageReceived(BMessage* msg) -{ - if (msg->what == B_ABOUT_REQUESTED) { - AboutRequested(); - } else { - inherited::MessageReceived(msg); +// copied from BeUtils.cpp +void AddFields(BMessage* to, const BMessage* from, const char* excludeList[], const char* includeList[]) { + if (to == from) return; + char* name; + type_code type; + int32 count; + for (int32 i = 0; from->GetInfo(B_ANY_TYPE, i, &name, &type, &count) == B_OK; i ++) { + if (excludeList && InList(excludeList, name)) continue; + if (includeList && !InList(includeList, name)) continue; + // replace existing data + to->RemoveName(name); + + const void* data; + ssize_t size; + for (int32 j = 0; j < count; j ++) { + if (from->FindData(name, type, j, &data, &size) == B_OK) { + // WTF why works AddData not for B_STRING_TYPE in R5.0.3? + if (type == B_STRING_TYPE) to->AddString(name, (const char*)data); + else if (type == B_MESSAGE_TYPE) { + BMessage m; + from->FindMessage(name, j, &m); + to->AddMessage(name, &m); + } else to->AddData(name, type, data, size); + } + } } } -// -------------------------------------------------- -static const char* -kAbout = -"PDF Writer for BeOS\n" -"© 2001, 2002 OpenBeOS\n" -"\n" -"\tPhilippe Houdoin - Project Leader\n" -"\tSimon Gauvin - GUI Design\n" -"\tMichael Pfeiffer - PDF Generation, Configuration, Interactive Features\n" -"\tCelerick Stephens - Documentation\n" -; - -void -HWindow::AboutRequested() -{ - BAlert *about = new BAlert("About PDF Writer", kAbout, "Cool"); - BTextView *v = about->TextView(); - if (v) { - rgb_color red = {255, 0, 51, 255}; - rgb_color blue = {0, 102, 255, 255}; - - v->SetStylable(true); - char *text = (char*)v->Text(); - char *s = text; - // set all Be in blue and red - while ((s = strstr(s, "Be")) != NULL) { - int32 i = s - text; - v->SetFontAndColor(i, i+1, NULL, 0, &blue); - v->SetFontAndColor(i+1, i+2, NULL, 0, &red); - s += 2; - } - // first text line - s = strchr(text, '\n'); - BFont font; - v->GetFontAndColor(0, &font); - font.SetSize(12); // font.SetFace(B_OUTLINED_FACE); - v->SetFontAndColor(0, s-text+1, &font, B_FONT_SIZE); - }; - about->Go(); +void AddString(BMessage* m, const char* name, const char* value) { + if (m->HasString(name, 0)) { + m->ReplaceString(name, value); + } else { + m->AddString(name, value); + } } diff --git a/src/add-ons/print/drivers/pdf/source/Utils.h b/src/add-ons/print/drivers/pdf/source/Utils.h index 777f1d10e2..663728d13a 100644 --- a/src/add-ons/print/drivers/pdf/source/Utils.h +++ b/src/add-ons/print/drivers/pdf/source/Utils.h @@ -37,6 +37,10 @@ THE SOFTWARE. #include +// adds fields to message or replaces existing fields (copy BeUtils.h) +void AddFields(BMessage* to, const BMessage* from, const char* excludeList[] = NULL, const char* includeList[] = NULL); +void AddString(BMessage* m, const char* name, const char* value); + class EscapeMessageFilter : public BMessageFilter { private: @@ -49,21 +53,6 @@ public: }; -class HWindow : public BWindow -{ -protected: - void Init(uint32 escape_msg); - -public: - typedef BWindow inherited; - - HWindow(BRect frame, const char *title, window_type type, uint32 flags, uint32 workspace = B_CURRENT_WORKSPACE, uint32 escape_msg = B_QUIT_REQUESTED); - HWindow(BRect frame, const char *title, window_look look, window_feel feel, uint32 flags, uint32 workspace = B_CURRENT_WORKSPACE, uint32 escape_msg = B_QUIT_REQUESTED); - - virtual void MessageReceived(BMessage* m); - virtual void AboutRequested(); -}; - #define BEGINS_CHAR(byte) ((byte & 0xc0) != 0x80) @@ -79,6 +68,7 @@ public: int32 CountItems() const; T* ItemAt(int32 index) const; void AddItem(T* p); + T* RemoveItem(int i); T* Items(); void SortItems(int (*comp)(const T**, const T**)); }; @@ -117,6 +107,11 @@ void TList::AddItem(T* p) { fList.AddItem(p); } +template +T* TList::RemoveItem(int i) { + return (T*)fList.RemoveItem(i); +} + template T* TList::Items() { diff --git a/src/add-ons/print/drivers/pdf/source/pdflib.h b/src/add-ons/print/drivers/pdf/source/pdflib.h index c296f7e4d7..4b3fd30cc0 100644 --- a/src/add-ons/print/drivers/pdf/source/pdflib.h +++ b/src/add-ons/print/drivers/pdf/source/pdflib.h @@ -1,33 +1,16 @@ /*---------------------------------------------------------------------------* | PDFlib - A library for generating PDF on the fly | +---------------------------------------------------------------------------+ - | Copyright (c) 1997-2002 PDFlib GmbH and Thomas Merz. All rights reserved. | + | Copyright (c) 1997-2003 Thomas Merz and PDFlib GmbH. All rights reserved. | +---------------------------------------------------------------------------+ - | This software is NOT in the public domain. It can be used under two | - | substantially different licensing terms: | | | - | The commercial license is available for a fee, and allows you to | - | - ship a commercial product based on PDFlib | - | - implement commercial Web services with PDFlib | - | - distribute (free or commercial) software when the source code is | - | not made available | - | Details can be found in the file PDFlib-license.pdf. | + | This software is subject to the PDFlib license. It is NOT in the | + | public domain. Extended versions and commercial licenses are | + | available, please check http://www.pdflib.com. | | | - | The "Aladdin Free Public License" doesn't require any license fee, | - | and allows you to | - | - develop and distribute PDFlib-based software for which the complete | - | source code is made available | - | - redistribute PDFlib non-commercially under certain conditions | - | - redistribute PDFlib on digital media for a fee if the complete | - | contents of the media are freely redistributable | - | Details can be found in the file aladdin-license.pdf. | - | | - | These conditions extend to ports to other programming languages. | - | PDFlib is distributed with no warranty of any kind. Commercial users, | - | however, will receive warranty and support statements in writing. | *---------------------------------------------------------------------------*/ -/* $Id: pdflib.h,v 1.1 2002/07/09 12:24:37 ejakowatz Exp $ +/* $Id: pdflib.h,v 1.2 2003/03/22 08:47:20 laplace Exp $ * * PDFlib public function and constant declarations * @@ -91,65 +74,124 @@ typedef struct PDF_s PDF; /* The API structure with function pointers. */ typedef struct PDFlib_api_s PDFlib_api; - -/* - * ---------------------------------------------------------------------- - * p_basic.c: general functions - * ---------------------------------------------------------------------- - */ - /* * The version defines below may be used to check the version of the * include file against the library. */ /* do not change this (version.sh will do it for you :) */ -#define PDFLIB_MAJORVERSION 4 /* PDFlib major version number */ +#define PDFLIB_MAJORVERSION 5 /* PDFlib major version number */ #define PDFLIB_MINORVERSION 0 /* PDFlib minor version number */ -#define PDFLIB_REVISION 3 /* PDFlib revision number */ -#define PDFLIB_VERSIONSTRING "4.0.3" /* The whole bunch */ +#define PDFLIB_REVISION 0 /* PDFlib revision number */ +#define PDFLIB_VERSIONSTRING "5.0.0b2" /* The whole bunch */ -/* - * Allow for the external and internal float type to be easily redefined. - * This is only for special applications which require improved accuracy, - * and not supported in the general case due to platform and binary - * compatibility issues. -*/ -/* #define float double */ -/* Retrieve a structure with PDFlib API function pointers (mainly for DLLs) */ -PDFLIB_API PDFlib_api * PDFLIB_CALL -PDF_get_api(void); +/* {{{ p_annots.c: file attachments, notes, and links + * ---------------------------------------------------------------------- + */ -/* Returns the PDFlib major version number. */ -PDFLIB_API int PDFLIB_CALL -PDF_get_majorversion(void); +/* Add a launch annotation (to a target of arbitrary file type). */ +PDFLIB_API void PDFLIB_CALL +PDF_add_launchlink(PDF *p, float llx, float lly, float urx, float ury, + const char *filename); -/* Returns the PDFlib minor version number. */ -PDFLIB_API int PDFLIB_CALL -PDF_get_minorversion(void); +/* Add a link annotation to a target within the current PDF file. */ +PDFLIB_API void PDFLIB_CALL +PDF_add_locallink(PDF *p, float llx, float lly, float urx, float ury, + int page, const char *optlist); + +/* Add a note annotation. icon is one of of "comment", "insert", "note", + * "paragraph", "newparagraph", "key", or "help". */ +PDFLIB_API void PDFLIB_CALL +PDF_add_note(PDF *p, float llx, float lly, float urx, float ury, + const char *contents, const char *title, const char *icon, int open); + +PDFLIB_API void PDFLIB_CALL +PDF_add_note2(PDF *p, float llx, float lly, float urx, float ury, + const char *contents, int len_cont, const char *title, int len_title, + const char *icon, int open); + +/* Add a file link annotation (to a PDF target). */ +PDFLIB_API void PDFLIB_CALL +PDF_add_pdflink(PDF *p, float llx, float lly, float urx, float ury, + const char *filename, int page, const char *optlist); + +/* Add a weblink annotation to a target URL on the Web. */ +PDFLIB_API void PDFLIB_CALL +PDF_add_weblink(PDF *p, float llx, float lly, float urx, float ury, + const char *url); + +/* Add a file attachment annotation. icon is one of "graph", "paperclip", + * "pushpin", or "tag". */ +PDFLIB_API void PDFLIB_CALL +PDF_attach_file(PDF *p, float llx, float lly, float urx, float ury, + const char *filename, const char *description, const char *author, + const char *mimetype, const char *icon); + +PDFLIB_API void PDFLIB_CALL +PDF_attach_file2(PDF *p, float llx, float lly, float urx, float ury, + const char *filename, int reserved, const char *description, int len_descr, + const char *author, int len_auth, const char *mimetype, const char *icon); + +/* Set the border color for all kinds of annotations. */ +PDFLIB_API void PDFLIB_CALL +PDF_set_border_color(PDF *p, float red, float green, float blue); + +/* Set the border dash style for all kinds of annotations. See PDF_setdash(). */ +PDFLIB_API void PDFLIB_CALL +PDF_set_border_dash(PDF *p, float b, float w); + +/* Set the border style for all kinds of annotations. style is "solid" or + * "dashed". */ +PDFLIB_API void PDFLIB_CALL +PDF_set_border_style(PDF *p, const char *style, float width); +/* }}} */ + + +/* {{{ p_basic.c: general functions + * ---------------------------------------------------------------------- + */ + +/* Add a new page to the document. */ +PDFLIB_API void PDFLIB_CALL +PDF_begin_page(PDF *p, float width, float height); /* Boot PDFlib (recommended although currently not required). */ PDFLIB_API void PDFLIB_CALL PDF_boot(void); -/* Shut down PDFlib (recommended although currently not required). */ +/* Close the generated PDF file, and release all document-related resources. */ PDFLIB_API void PDFLIB_CALL -PDF_shutdown(void); +PDF_close(PDF *p); -/* Create a new PDF object with client-supplied error handling and memory - allocation routines. */ -typedef void (*errorproc_t)(PDF *p1, int type, const char *msg); -typedef void* (*allocproc_t)(PDF *p2, size_t size, const char *caller); -typedef void* (*reallocproc_t)(PDF *p3, - void *mem, size_t size, const char *caller); -typedef void (*freeproc_t)(PDF *p4, void *mem); +/* Delete the PDF object, and free all internal resources. */ +PDFLIB_API void PDFLIB_CALL +PDF_delete(PDF *p); -PDFLIB_API PDF * PDFLIB_CALL -PDF_new2(errorproc_t errorhandler, allocproc_t allocproc, - reallocproc_t reallocproc, freeproc_t freeproc, void *opaque); +/* Finish the page. */ +PDFLIB_API void PDFLIB_CALL +PDF_end_page(PDF *p); -/* Fetch opaque application pointer stored in PDFlib (for multi-threading). */ +/* Retrieve a structure with PDFlib API function pointers (mainly for DLLs). + * Although this function is published here, it is not supposed to be used + * directly by clients. Use PDF_boot_dll() (in pdflibdl.c) instead. */ +PDFLIB_API const PDFlib_api * PDFLIB_CALL +PDF_get_api(void); + +/* Get the contents of the PDF output buffer. The result must be used by + * the client before calling any other PDFlib function. */ +PDFLIB_API const char * PDFLIB_CALL +PDF_get_buffer(PDF *p, long *size); + +/* Depreceated: use PDF_get_value() */ +PDFLIB_API int PDFLIB_CALL +PDF_get_majorversion(void); + +/* Depreceated: use PDF_get_value() */ +PDFLIB_API int PDFLIB_CALL +PDF_get_minorversion(void); + +/* Fetch the opaque application pointer stored in PDFlib. */ PDFLIB_API void * PDFLIB_CALL PDF_get_opaque(PDF *p); @@ -158,9 +200,17 @@ PDF_get_opaque(PDF *p); PDFLIB_API PDF * PDFLIB_CALL PDF_new(void); -/* Delete the PDF object, and free all internal resources. */ -PDFLIB_API void PDFLIB_CALL -PDF_delete(PDF *p); +/* Create a new PDF object with client-supplied error handling and memory + * allocation routines. */ +typedef void (*errorproc_t)(PDF *p1, int errortype, const char *msg); +typedef void* (*allocproc_t)(PDF *p2, size_t size, const char *caller); +typedef void* (*reallocproc_t)(PDF *p3, + void *mem, size_t size, const char *caller); +typedef void (*freeproc_t)(PDF *p4, void *mem); + +PDFLIB_API PDF * PDFLIB_CALL +PDF_new2(errorproc_t errorhandler, allocproc_t allocproc, + reallocproc_t reallocproc, freeproc_t freeproc, void *opaque); /* Create a new PDF file using the supplied file name. */ PDFLIB_API int PDFLIB_CALL @@ -175,22 +225,20 @@ typedef size_t (*writeproc_t)(PDF *p1, void *data, size_t size); PDFLIB_API void PDFLIB_CALL PDF_open_mem(PDF *p, writeproc_t writeproc); -/* Close the generated PDF file, and release all document-related resources. */ +/* Shut down PDFlib (recommended although currently not required). */ PDFLIB_API void PDFLIB_CALL -PDF_close(PDF *p); +PDF_shutdown(void); -/* Add a new page to the document. */ -PDFLIB_API void PDFLIB_CALL -PDF_begin_page(PDF *p, float width, float height); +/* + * Error classes are deprecated; use PDF_TRY/PDF_CATCH instead. + * Note that old-style error handlers are still supported, but + * they will always receive type PDF_NonfatalError (for warnings) + * or PDF_UnknownError (for other exceptions). + */ -/* Finish the page. */ -PDFLIB_API void PDFLIB_CALL -PDF_end_page(PDF *p); - -/* PDFlib exceptions which may be handled by a user-supplied error handler */ #define PDF_MemoryError 1 #define PDF_IOError 2 -#define PDF_RuntimeError 3 +#define PDF_RuntimeError 3 #define PDF_IndexError 4 #define PDF_TypeError 5 #define PDF_DivisionByZero 6 @@ -198,213 +246,73 @@ PDF_end_page(PDF *p); #define PDF_SyntaxError 8 #define PDF_ValueError 9 #define PDF_SystemError 10 + #define PDF_NonfatalError 11 #define PDF_UnknownError 12 +/* }}} */ -/* - * ---------------------------------------------------------------------- - * p_params.c: parameter handling - * ---------------------------------------------------------------------- + +/*{{{ p_block.c: Variable Data Processing with blocks (requires the PDI library) + * -------------------------------------------------------------------------- */ -/* Set some PDFlib parameter with string type. */ -PDFLIB_API void PDFLIB_CALL -PDF_set_parameter(PDF *p, const char *key, const char *value); - -/* Set the value of some PDFlib parameter with float type. */ -PDFLIB_API void PDFLIB_CALL -PDF_set_value(PDF *p, const char *key, float value); - -/* Get the contents of some PDFlib parameter with string type. */ -PDFLIB_API const char * PDFLIB_CALL -PDF_get_parameter(PDF *p, const char *key, float modifier); - -/* Get the value of some PDFlib parameter with float type. */ -PDFLIB_API float PDFLIB_CALL -PDF_get_value(PDF *p, const char *key, float modifier); - - -/* - * ---------------------------------------------------------------------- - * p_font.c: text and font handling - * ---------------------------------------------------------------------- - */ - -/* Search a font, and prepare it for later use. The metrics will be - loaded, and if embed is nonzero, the font file will be checked, but not - yet used. Encoding is one of "builtin", "macroman", "winansi", "host", or - a user-defined encoding name, or the name of a CMap. */ +/* Process an image block according to its properties. */ PDFLIB_API int PDFLIB_CALL -PDF_findfont(PDF *p, const char *fontname, const char *encoding, int embed); +PDF_fill_imageblock(PDF *p, int page, const char *blockname, + int image, const char *optlist); -/* Set the current font in the given size, using a font handle returned by - PDF_findfont(). */ -PDFLIB_API void PDFLIB_CALL -PDF_setfont(PDF *p, int font, float fontsize); - -/* Request a glyph name from a custom encoding (unsupported). */ -PDFLIB_API const char * PDFLIB_CALL -PDF_encoding_get_name(PDF *p, const char *encoding, int slot); - -/* - * ---------------------------------------------------------------------- - * p_text.c: text output - * ---------------------------------------------------------------------- - */ - -/* Print text in the current font and size at the current position. */ -PDFLIB_API void PDFLIB_CALL -PDF_show(PDF *p, const char *text); - -/* Print text in the current font at (x, y). */ -PDFLIB_API void PDFLIB_CALL -PDF_show_xy(PDF *p, const char *text, float x, float y); - -/* Print text at the next line. The spacing between lines is determined by - the "leading" parameter. */ -PDFLIB_API void PDFLIB_CALL -PDF_continue_text(PDF *p, const char *text); - -/* Format text in the current font and size into the supplied text box - according to the requested formatting mode, which must be one of - "left", "right", "center", "justify", or "fulljustify". If width and height - are 0, only a single line is placed at the point (left, top) in the - requested mode. */ +/* Process a PDF block according to its properties. */ PDFLIB_API int PDFLIB_CALL -PDF_show_boxed(PDF *p, const char *text, float left, float top, - float width, float height, const char *hmode, const char *feature); +PDF_fill_pdfblock(PDF *p, int page, const char *blockname, + int contents, const char *optlist); -/* This function is unsupported, and not considered part of the PDFlib API! */ -PDFLIB_API void PDFLIB_CALL -PDF_set_text_matrix(PDF *p, - float a, float b, float c, float d, float e, float f); - -/* Set the text output position. */ -PDFLIB_API void PDFLIB_CALL -PDF_set_text_pos(PDF *p, float x, float y); - -/* Return the width of text in an arbitrary font. */ -PDFLIB_API float PDFLIB_CALL -PDF_stringwidth(PDF *p, const char *text, int font, float size); - -/* Function duplicates with explicit string length for use with -strings containing null characters. These are for C and C++ clients only, -but are used internally for the other language bindings. */ - -/* Same as PDF_show() but with explicit string length. */ -PDFLIB_API void PDFLIB_CALL -PDF_show2(PDF *p, const char *text, int len); - -/* Same as PDF_show_xy() but with explicit string length. */ -PDFLIB_API void PDFLIB_CALL -PDF_show_xy2(PDF *p, const char *text, int len, float x, float y); - -/* Same as PDF_continue_text but with explicit string length. */ -PDFLIB_API void PDFLIB_CALL -PDF_continue_text2(PDF *p, const char *text, int len); - -/* Same as PDF_stringwidth but with explicit string length. */ -PDFLIB_API float PDFLIB_CALL -PDF_stringwidth2(PDF *p, const char *text, int len, int font, float size); +/* Process a text block according to its properties. */ +PDFLIB_API int PDFLIB_CALL +PDF_fill_textblock(PDF *p, int page, const char *blockname, + const char *text, int len, const char *optlist); +/* }}} */ -/* - * ---------------------------------------------------------------------- - * p_gstate.c: graphics state +/* {{{ p_color.c: color handling * ---------------------------------------------------------------------- */ -/* Maximum length of dash arrays */ -#define MAX_DASH_LENGTH 8 +/* Make a named spot color from the current color. */ +PDFLIB_API int PDFLIB_CALL +PDF_makespotcolor(PDF *p, const char *spotname, int reserved); -/* Set the current dash pattern to b black and w white units. */ +/* Set the current color space and color. fstype is "fill", "stroke", or "both". + */ PDFLIB_API void PDFLIB_CALL -PDF_setdash(PDF *p, float b, float w); +PDF_setcolor(PDF *p, const char *fstype, const char *colorspace, + float c1, float c2, float c3, float c4); -/* Set a more complicated dash pattern defined by an array. */ +/* The following six functions are deprecated, use PDF_setcolor() instead. */ PDFLIB_API void PDFLIB_CALL -PDF_setpolydash(PDF *p, float *dasharray, int length); +PDF_setgray(PDF *p, float gray); -/* Set the flatness to a value between 0 and 100 inclusive. */ PDFLIB_API void PDFLIB_CALL -PDF_setflat(PDF *p, float flatness); +PDF_setgray_fill(PDF *p, float gray); -/* Set the line join parameter to a value between 0 and 2 inclusive. */ PDFLIB_API void PDFLIB_CALL -PDF_setlinejoin(PDF *p, int linejoin); +PDF_setgray_stroke(PDF *p, float gray); -/* Set the linecap parameter to a value between 0 and 2 inclusive. */ PDFLIB_API void PDFLIB_CALL -PDF_setlinecap(PDF *p, int linecap); +PDF_setrgbcolor(PDF *p, float red, float green, float blue); -/* Set the miter limit to a value greater than or equal to 1. */ PDFLIB_API void PDFLIB_CALL -PDF_setmiterlimit(PDF *p, float miter); +PDF_setrgbcolor_fill(PDF *p, float red, float green, float blue); -/* Set the current linewidth to width. */ PDFLIB_API void PDFLIB_CALL -PDF_setlinewidth(PDF *p, float width); - -/* Reset all color and graphics state parameters to their defaults. */ -PDFLIB_API void PDFLIB_CALL -PDF_initgraphics(PDF *p); - -/* Save the current graphics state. */ -PDFLIB_API void PDFLIB_CALL -PDF_save(PDF *p); - -/* Restore the most recently saved graphics state. */ -PDFLIB_API void PDFLIB_CALL -PDF_restore(PDF *p); - -/* Translate the origin of the coordinate system. */ -PDFLIB_API void PDFLIB_CALL -PDF_translate(PDF *p, float tx, float ty); - -/* Scale the coordinate system. */ -PDFLIB_API void PDFLIB_CALL -PDF_scale(PDF *p, float sx, float sy); - -/* Rotate the coordinate system by phi degrees. */ -PDFLIB_API void PDFLIB_CALL -PDF_rotate(PDF *p, float phi); - -/* Skew the coordinate system in x and y direction by alpha and beta degrees. */ -PDFLIB_API void PDFLIB_CALL -PDF_skew(PDF *p, float alpha, float beta); - -/* Concatenate a matrix to the current transformation matrix. */ -PDFLIB_API void PDFLIB_CALL -PDF_concat(PDF *p, float a, float b, float c, float d, float e, float f); - -/* Explicitly set the current transformation matrix. */ -PDFLIB_API void PDFLIB_CALL -PDF_setmatrix(PDF *p, float a, float b, float c, float d, float e, float f); +PDF_setrgbcolor_stroke(PDF *p, float red, float green, float blue); +/* }}} */ -/* - * ---------------------------------------------------------------------- - * p_draw.c: path construction, painting, and clipping +/* {{{ p_draw.c: path construction, painting, and clipping * ---------------------------------------------------------------------- */ -/* Set the current point. */ -PDFLIB_API void PDFLIB_CALL -PDF_moveto(PDF *p, float x, float y); - -/* Draw a line from the current point to (x, y). */ -PDFLIB_API void PDFLIB_CALL -PDF_lineto(PDF *p, float x, float y); - -/* Draw a Bezier curve from the current point, using 3 more control points. */ -PDFLIB_API void PDFLIB_CALL -PDF_curveto(PDF *p, float x1, float y1, float x2, float y2, float x3, float y3); - -/* Draw a circle with center (x, y) and radius r. */ -PDFLIB_API void PDFLIB_CALL -PDF_circle(PDF *p, float x, float y, float r); - /* Draw a counterclockwise circular arc from alpha to beta degrees. */ PDFLIB_API void PDFLIB_CALL PDF_arc(PDF *p, float x, float y, float r, float alpha, float beta); @@ -413,22 +321,35 @@ PDF_arc(PDF *p, float x, float y, float r, float alpha, float beta); PDFLIB_API void PDFLIB_CALL PDF_arcn(PDF *p, float x, float y, float r, float alpha, float beta); -/* Draw a rectangle at lower left (x, y) with width and height. */ +/* Draw a circle with center (x, y) and radius r. */ PDFLIB_API void PDFLIB_CALL -PDF_rect(PDF *p, float x, float y, float width, float height); +PDF_circle(PDF *p, float x, float y, float r); + +/* Use the current path as clipping path. */ +PDFLIB_API void PDFLIB_CALL +PDF_clip(PDF *p); /* Close the current path. */ PDFLIB_API void PDFLIB_CALL PDF_closepath(PDF *p); -/* Stroke the path with the current color and line width, and clear it. */ +/* Close the path, fill, and stroke it. */ PDFLIB_API void PDFLIB_CALL -PDF_stroke(PDF *p); +PDF_closepath_fill_stroke(PDF *p); /* Close the path, and stroke it. */ PDFLIB_API void PDFLIB_CALL PDF_closepath_stroke(PDF *p); +/* Draw a Bezier curve from the current point, using 3 more control points. */ +PDFLIB_API void PDFLIB_CALL +PDF_curveto(PDF *p, + float x_1, float y_1, float x_2, float y_2, float x_3, float y_3); + +/* End the current path without filling or stroking it. */ +PDFLIB_API void PDFLIB_CALL +PDF_endpath(PDF *p); + /* Fill the interior of the path with the current fill color. */ PDFLIB_API void PDFLIB_CALL PDF_fill(PDF *p); @@ -437,62 +358,276 @@ PDF_fill(PDF *p); PDFLIB_API void PDFLIB_CALL PDF_fill_stroke(PDF *p); -/* Close the path, fill, and stroke it. */ +/* Draw a line from the current point to (x, y). */ PDFLIB_API void PDFLIB_CALL -PDF_closepath_fill_stroke(PDF *p); +PDF_lineto(PDF *p, float x, float y); -/* End the current path without filling or stroking it. */ +/* Draw a line from the current point to (cp + (x, y)) (unsupported). */ PDFLIB_API void PDFLIB_CALL -PDF_endpath(PDF *p); +PDF_rlineto(PDF *p, float x, float y); -/* Use the current path as clipping path. */ +/* Set the current point. */ PDFLIB_API void PDFLIB_CALL -PDF_clip(PDF *p); +PDF_moveto(PDF *p, float x, float y); + +/* Draw a Bezier curve from the current point using relative coordinates + (unsupported). */ +PDFLIB_API void PDFLIB_CALL +PDF_rcurveto(PDF *p, + float x_1, float y_1, float x_2, float y_2, float x_3, float y_3); + +/* Draw a rectangle at lower left (x, y) with width and height. */ +PDFLIB_API void PDFLIB_CALL +PDF_rect(PDF *p, float x, float y, float width, float height); + +/* Set the new current point relative the old current point (unsupported). */ +PDFLIB_API void PDFLIB_CALL +PDF_rmoveto(PDF *p, float x, float y); + +/* Stroke the path with the current color and line width, and clear it. */ +PDFLIB_API void PDFLIB_CALL +PDF_stroke(PDF *p); + +/* }}} */ -/* - * ---------------------------------------------------------------------- - * p_color.c: color handling +/* {{{ p_encoding.c: encoding handling * ---------------------------------------------------------------------- */ -/* Deprecated, use PDF_setcolor(p, "fill", "gray", g, 0, 0, 0) instead. */ -PDFLIB_API void PDFLIB_CALL -PDF_setgray_fill(PDF *p, float gray); +/* Request a glyph name from a custom encoding (unsupported). */ +PDFLIB_API const char * PDFLIB_CALL +PDF_encoding_get_glyphname(PDF *p, const char *encoding, int slot); -/* Deprecated, use PDF_setcolor(p, "stroke", "gray", g, 0, 0, 0) instead. */ -PDFLIB_API void PDFLIB_CALL -PDF_setgray_stroke(PDF *p, float gray); - -/* Deprecated, use PDF_setcolor(p, "both", "gray", g, 0, 0, 0) instead. */ -PDFLIB_API void PDFLIB_CALL -PDF_setgray(PDF *p, float gray); - -/* Deprecated, use PDF_setcolor(p, "fill", "rgb", red, green, blue, 0). */ -PDFLIB_API void PDFLIB_CALL -PDF_setrgbcolor_fill(PDF *p, float red, float green, float blue); - -/* Deprecated, use PDF_setcolor(p, "stroke", "rgb", red, green, blue, 0). */ -PDFLIB_API void PDFLIB_CALL -PDF_setrgbcolor_stroke(PDF *p, float red, float green, float blue); - -/* Deprecated, use PDF_setcolor(p, "both", "rgb", red, green, blue, 0). */ -PDFLIB_API void PDFLIB_CALL -PDF_setrgbcolor(PDF *p, float red, float green, float blue); - -/* Make a named spot color from the current color. */ +/* Request a glyph unicode value from a custom encoding (unsupported). */ PDFLIB_API int PDFLIB_CALL -PDF_makespotcolor(PDF *p, const char *spotname, int len); +PDF_encoding_get_unicode(PDF *p, const char *encoding, int slot); -/* Set the current color space and color. type is "fill", "stroke", or "both".*/ +/* Add a glyph name to a custom encoding. */ PDFLIB_API void PDFLIB_CALL -PDF_setcolor(PDF *p, const char *fstype, const char *colorspace, - float c1, float c2, float c3, float c4); +PDF_encoding_set_char(PDF *p, const char *encoding, int slot, + const char *glyphname, int uv); +/* }}} */ -/* +/* {{{ p_font.c: text and font handling * ---------------------------------------------------------------------- - * p_pattern.c: pattern definition + */ + +/* Search a font, and prepare it for later use. PDF_load_font() is + * recommended. */ +PDFLIB_API int PDFLIB_CALL +PDF_findfont(PDF *p, const char *fontname, const char *encoding, int embed); + +/* Request a glyph ID value from a font (unsupported). */ +PDFLIB_API int PDFLIB_CALL +PDF_get_glyphid(PDF *p, int font, int code); + +/* Open and search a font, and prepare it for later use. */ +PDFLIB_API int PDFLIB_CALL +PDF_load_font(PDF *p, const char *fontname, int reserved, + const char *encoding, const char *optlist); + +/* Set the current font in the given size, using a font handle returned by + * PDF_load_font(). */ +PDFLIB_API void PDFLIB_CALL +PDF_setfont(PDF *p, int font, float fontsize); +/* }}} */ + + +/* {{{ p_gstate.c: graphics state + * ---------------------------------------------------------------------- + */ + +/* Maximum length of dash arrays */ +#define MAX_DASH_LENGTH 8 + +/* Concatenate a matrix to the current transformation matrix. */ +PDFLIB_API void PDFLIB_CALL +PDF_concat(PDF *p, float a, float b, float c, float d, float e, float f); + +/* Reset all color and graphics state parameters to their defaults. */ +PDFLIB_API void PDFLIB_CALL +PDF_initgraphics(PDF *p); + +/* Restore the most recently saved graphics state. */ +PDFLIB_API void PDFLIB_CALL +PDF_restore(PDF *p); + +/* Rotate the coordinate system by phi degrees. */ +PDFLIB_API void PDFLIB_CALL +PDF_rotate(PDF *p, float phi); + +/* Save the current graphics state. */ +PDFLIB_API void PDFLIB_CALL +PDF_save(PDF *p); + +/* Scale the coordinate system. */ +PDFLIB_API void PDFLIB_CALL +PDF_scale(PDF *p, float sx, float sy); + +/* Set the current dash pattern to b black and w white units. */ +PDFLIB_API void PDFLIB_CALL +PDF_setdash(PDF *p, float b, float w); + +/* Set a more complicated dash pattern defined by an optlist. */ +PDFLIB_API void PDFLIB_CALL +PDF_setdashpattern(PDF *p, const char *optlist); + +/* Set the flatness to a value between 0 and 100 inclusive. */ +PDFLIB_API void PDFLIB_CALL +PDF_setflat(PDF *p, float flatness); + +/* Set the linecap parameter to a value between 0 and 2 inclusive. */ +PDFLIB_API void PDFLIB_CALL +PDF_setlinecap(PDF *p, int linecap); + +/* Set the linejoin parameter to a value between 0 and 2 inclusive. */ +PDFLIB_API void PDFLIB_CALL +PDF_setlinejoin(PDF *p, int linejoin); + +/* Set the current linewidth to width. */ +PDFLIB_API void PDFLIB_CALL +PDF_setlinewidth(PDF *p, float width); + +/* Explicitly set the current transformation matrix. */ +PDFLIB_API void PDFLIB_CALL +PDF_setmatrix(PDF *p, float a, float b, float c, float d, float e, float f); + +/* Set the miter limit to a value greater than or equal to 1. */ +PDFLIB_API void PDFLIB_CALL +PDF_setmiterlimit(PDF *p, float miter); + +/* Deprecated, use PDF_setdashpattern() instead. */ +PDFLIB_API void PDFLIB_CALL +PDF_setpolydash(PDF *p, float *dasharray, int length); + +/* Skew the coordinate system in x and y direction by alpha and beta degrees. */ +PDFLIB_API void PDFLIB_CALL +PDF_skew(PDF *p, float alpha, float beta); + +/* Translate the origin of the coordinate system. */ +PDFLIB_API void PDFLIB_CALL +PDF_translate(PDF *p, float tx, float ty); +/* }}} */ + + +/* {{{ p_hyper.c: bookmarks and document info fields + * ---------------------------------------------------------------------- + */ + +/* Add a nested bookmark under parent, or a new top-level bookmark if + * parent = 0. Returns a bookmark descriptor which may be + * used as parent for subsequent nested bookmarks. If open = 1, child + * bookmarks will be folded out, and invisible if open = 0. */ +PDFLIB_API int PDFLIB_CALL +PDF_add_bookmark(PDF *p, const char *text, int parent, int open); + +PDFLIB_API int PDFLIB_CALL +PDF_add_bookmark2(PDF *p, const char *text, int len, int parent, int open); + +/* Create a named destination on an arbitrary page in the current document. */ +PDFLIB_API void PDFLIB_CALL +PDF_add_nameddest(PDF *p, const char *name, int reserved, const char *optlist); + +/* Fill document information field key with value. key is one of "Subject", + * "Title", "Creator", "Author", "Keywords", or a user-defined key. */ +PDFLIB_API void PDFLIB_CALL +PDF_set_info(PDF *p, const char *key, const char *value); + +PDFLIB_API void PDFLIB_CALL +PDF_set_info2(PDF *p, const char *key, const char *value, int len); +/* }}} */ + + +/* {{{ p_icc.c: ICC profile handling + * ---------------------------------------------------------------------- + */ + +/* Search an ICC profile, and prepare it for later use. */ +PDFLIB_API int PDFLIB_CALL +PDF_load_iccprofile(PDF *p, const char *profilename, int reserved, + const char *optlist); +/* }}} */ + + +/* {{{ p_image.c: image handling + * ---------------------------------------------------------------------- + */ + +/* Add an existing image as thumbnail for the current page. */ +PDFLIB_API void PDFLIB_CALL +PDF_add_thumbnail(PDF *p, int image); + +/* Close an image retrieved with PDF_load_image(). */ +PDFLIB_API void PDFLIB_CALL +PDF_close_image(PDF *p, int image); + +/* Place an image or template at (x, y) with various options. */ +PDFLIB_API void PDFLIB_CALL +PDF_fit_image(PDF *p, int image, float x, float y, const char *optlist); + +/* Open a (disk-based or virtual) image file with various options. */ +PDFLIB_API int PDFLIB_CALL +PDF_load_image(PDF *p, const char *imagetype, const char *filename, + int reserved, const char *optlist); + +/* Deprecated, use PDF_load_image() instead. */ +PDFLIB_API int PDFLIB_CALL +PDF_open_CCITT(PDF *p, const char *filename, int width, int height, + int BitReverse, int K, int BlackIs1); + +/* Deprecated, use PDF_load_image() with virtual files instead. */ +PDFLIB_API int PDFLIB_CALL +PDF_open_image(PDF *p, const char *imagetype, const char *source, + const char *data, long length, int width, int height, int components, + int bpc, const char *params); + +/* Deprecated, use PDF_load_image() instead. */ +PDFLIB_API int PDFLIB_CALL +PDF_open_image_file(PDF *p, const char *imagetype, const char *filename, + const char *stringparam, int intparam); + +/* Deprecated, use PDF_fit_image() instead. */ +PDFLIB_API void PDFLIB_CALL +PDF_place_image(PDF *p, int image, float x, float y, float scale); +/* }}} */ + + +/* {{{ p_kerning.c: font kerning + * ---------------------------------------------------------------------- + */ + +/* Request the amount of kerning between two characters in a specified font. + (unsupported) */ +PDFLIB_API float PDFLIB_CALL +PDF_get_kern_amount(PDF *p, int font, int firstchar, int secondchar); +/* }}} */ + + +/* {{{ p_params.c: parameter handling + * ---------------------------------------------------------------------- + */ + +/* Get the contents of some PDFlib parameter with string type. */ +PDFLIB_API const char * PDFLIB_CALL +PDF_get_parameter(PDF *p, const char *key, float modifier); + +/* Get the value of some PDFlib parameter with float type. */ +PDFLIB_API float PDFLIB_CALL +PDF_get_value(PDF *p, const char *key, float modifier); + +/* Set some PDFlib parameter with string type. */ +PDFLIB_API void PDFLIB_CALL +PDF_set_parameter(PDF *p, const char *key, const char *value); + +/* Set the value of some PDFlib parameter with float type. */ +PDFLIB_API void PDFLIB_CALL +PDF_set_value(PDF *p, const char *key, float value); +/* }}} */ + + +/* {{{ p_pattern.c: pattern definition * ---------------------------------------------------------------------- */ @@ -504,11 +639,100 @@ PDF_begin_pattern(PDF *p, /* Finish a pattern definition. */ PDFLIB_API void PDFLIB_CALL PDF_end_pattern(PDF *p); +/* }}} */ -/* +/* {{{ p_pdi.c: PDF import (requires the PDI library) * ---------------------------------------------------------------------- - * p_template.c: template definition + */ + +/* Close all open page handles, and close the input PDF document. */ +PDFLIB_API void PDFLIB_CALL +PDF_close_pdi(PDF *p, int doc); + +/* Close the page handle, and free all page-related resources. */ +PDFLIB_API void PDFLIB_CALL +PDF_close_pdi_page(PDF *p, int page); + +/* Place an imported PDF page with the lower left corner at (x, y) with + * various options. */ +PDFLIB_API void PDFLIB_CALL +PDF_fit_pdi_page(PDF *p, int page, float x, float y, const char *optlist); + +/* Get the contents of some PDI document parameter with string type. */ +PDFLIB_API const char *PDFLIB_CALL +PDF_get_pdi_parameter(PDF *p, const char *key, int doc, int page, + int reserved, int *len); + +/* Get the contents of some PDI document parameter with numerical type. */ +PDFLIB_API float PDFLIB_CALL +PDF_get_pdi_value(PDF *p, const char *key, int doc, int page, int reserved); + +/* Open a (disk-based or virtual) PDF document and prepare it for later use. */ +PDFLIB_API int PDFLIB_CALL +PDF_open_pdi(PDF *p, const char *filename, const char *optlist, int reserved); + +/* Open an existing PDF document with callback functions for file access. */ +PDFLIB_API int PDFLIB_CALL +PDF_open_pdi_callback(PDF *p, void *opaque, size_t filesize, + size_t (*readproc)(void *opaque, void *buffer, size_t size), + int (*seekproc)(void *opaque, long offset), + const char *optlist); + +/* Prepare a page for later use with PDF_place_pdi_page(). */ +PDFLIB_API int PDFLIB_CALL +PDF_open_pdi_page(PDF *p, int doc, int pagenumber, const char *optlist); + +/* Deprecated, use PDF_fit_pdi_page( ) instead. */ +PDFLIB_API void PDFLIB_CALL +PDF_place_pdi_page(PDF *p, int page, float x, float y, float sx, float sy); + +/* Perform various actions on a PDI document. */ +PDFLIB_API int PDFLIB_CALL +PDF_process_pdi(PDF *p, int doc, int page, const char *optlist); +/* }}} */ + + +/* {{{ p_resource.c: resources and virtual file system handling + * ---------------------------------------------------------------------- + */ + +/* Create a new virtual file. */ +PDFLIB_API void PDFLIB_CALL +PDF_create_pvf(PDF *p, const char *filename, int reserved, + const void *data, size_t size, const char *optlist); + +/* Delete a virtual file. */ +PDFLIB_API int PDFLIB_CALL +PDF_delete_pvf(PDF *p, const char *filename, int reserved); +/* }}} */ + + +/* {{{ p_shading.c: shadings + * ---------------------------------------------------------------------- + */ + +/* Define a color blend (smooth shading) from the current fill color to the + * supplied color. */ +PDFLIB_API int PDFLIB_CALL +PDF_shading(PDF *p, + const char *shtype, + float x_0, float y_0, + float x_1, float y_1, + float c_1, float c_2, float c_3, float c_4, + const char *optlist); + +/* Define a shading pattern using a shading object. */ +PDFLIB_API int PDFLIB_CALL +PDF_shading_pattern(PDF *p, int shading, const char *optlist); + +/* Fill an area with a shading, based on a shading object. */ +PDFLIB_API void PDFLIB_CALL +PDF_shfill(PDF *p, int shading); +/* }}} */ + + +/* {{{ p_template.c: template definition * ---------------------------------------------------------------------- */ @@ -519,176 +743,415 @@ PDF_begin_template(PDF *p, float width, float height); /* Finish a template definition. */ PDFLIB_API void PDFLIB_CALL PDF_end_template(PDF *p); +/* }}} */ -/* - * ---------------------------------------------------------------------- - * p_image.c: image handling +/* {{{ p_text.c: text output * ---------------------------------------------------------------------- */ -/* Place an image or template with the lower left corner at (x, y), - and scale it. */ -PDFLIB_API void PDFLIB_CALL -PDF_place_image(PDF *p, int image, float x, float y, float scale); +/* Function duplicates with explicit string length for use with +strings containing null characters. These are for C and C++ clients only, +but are used internally for the other language bindings. */ -/* Use image data from a variety of data sources. Supported types are - "jpeg", "ccitt", "raw". Supported sources are "memory", "fileref", "url". - len is only used for type="raw", params is only used for type="ccitt". */ +/* Print text at the next line. The spacing between lines is determined by + * the "leading" parameter. */ +PDFLIB_API void PDFLIB_CALL +PDF_continue_text(PDF *p, const char *text); + +/* Same as PDF_continue_text but with explicit string length. */ +PDFLIB_API void PDFLIB_CALL +PDF_continue_text2(PDF *p, const char *text, int len); + +/* Place a single text line at (x, y) with various options. */ +PDFLIB_API void PDFLIB_CALL +PDF_fit_textline(PDF *p, const char *text, int len, float x, float y, + const char *optlist); + +/* This function is unsupported, and not considered part of the PDFlib API! */ +PDFLIB_API void PDFLIB_CALL +PDF_set_text_matrix(PDF *p, + float a, float b, float c, float d, float e, float f); + +/* Set the text output position. */ +PDFLIB_API void PDFLIB_CALL +PDF_set_text_pos(PDF *p, float x, float y); + +/* Print text in the current font and size at the current position. */ +PDFLIB_API void PDFLIB_CALL +PDF_show(PDF *p, const char *text); + +/* Same as PDF_show() but with explicit string length. */ +PDFLIB_API void PDFLIB_CALL +PDF_show2(PDF *p, const char *text, int len); + +/* Format text in the current font and size into the supplied text box + * according to the requested formatting mode, which must be one of + * "left", "right", "center", "justify", or "fulljustify". If width and height + * are 0, only a single line is placed at the point (left, top) in the + * requested mode. */ PDFLIB_API int PDFLIB_CALL -PDF_open_image(PDF *p, const char *imagetype, const char *source, - const char *data, long length, int width, int height, int components, - int bpc, const char *params); +PDF_show_boxed(PDF *p, const char *text, float left, float top, + float width, float height, const char *hmode, const char *feature); -/* Open an image file. Supported types are "jpeg", "tiff", "gif", and "png" - stringparam is either "", "mask", "masked", or "page". intparam is either 0, - the image number of the applied mask, or the page. */ -PDFLIB_API int PDFLIB_CALL -PDF_open_image_file(PDF *p, const char *imagetype, const char *filename, - const char *stringparam, int intparam); - -/* Close an image retrieved with one of the PDF_open_image*() functions. */ +/* Print text in the current font at (x, y). */ PDFLIB_API void PDFLIB_CALL -PDF_close_image(PDF *p, int image); +PDF_show_xy(PDF *p, const char *text, float x, float y); -/* Add an existing image as thumbnail for the current page. */ +/* Same as PDF_show_xy() but with explicit string length. */ PDFLIB_API void PDFLIB_CALL -PDF_add_thumbnail(PDF *p, int image); +PDF_show_xy2(PDF *p, const char *text, int len, float x, float y); - -/* - * ---------------------------------------------------------------------- - * p_ccitt.c: fax-compressed data processing - * ---------------------------------------------------------------------- - */ - -/* Open a raw CCITT image. */ -PDFLIB_API int PDFLIB_CALL -PDF_open_CCITT(PDF *p, const char *filename, int width, int height, - int BitReverse, int K, int BlackIs1); - - -/* - * ---------------------------------------------------------------------- - * p_hyper.c: bookmarks and document info fields - * ---------------------------------------------------------------------- - */ - -/* Add a nested bookmark under parent, or a new top-level bookmark if - parent = 0. Returns a bookmark descriptor which may be - used as parent for subsequent nested bookmarks. If open = 1, child - bookmarks will be folded out, and invisible if open = 0. */ -PDFLIB_API int PDFLIB_CALL -PDF_add_bookmark(PDF *p, const char *text, int parent, int open); - - -/* Fill document information field key with value. key is one of "Subject", - "Title", "Creator", "Author", "Keywords", or a user-defined key. */ -PDFLIB_API void PDFLIB_CALL -PDF_set_info(PDF *p, const char *key, const char *value); - - -/* - * ---------------------------------------------------------------------- - * p_annots.c: file attachments, notes, and links - * ---------------------------------------------------------------------- - */ - -/* Add a file attachment annotation. icon is one of "graph", "paperclip", - "pushpin", or "tag". */ -PDFLIB_API void PDFLIB_CALL -PDF_attach_file(PDF *p, float llx, float lly, float urx, float ury, - const char *filename, const char *description, const char *author, - const char *mimetype, const char *icon); - -/* Add a note annotation. icon is one of of "comment", "insert", "note", - "paragraph", "newparagraph", "key", or "help". */ -PDFLIB_API void PDFLIB_CALL -PDF_add_note(PDF *p, float llx, float lly, float urx, float ury, - const char *contents, const char *title, const char *icon, int open); - -/* Add a file link annotation (to a PDF target). */ -PDFLIB_API void PDFLIB_CALL -PDF_add_pdflink(PDF *p, float llx, float lly, float urx, float ury, - const char *filename, int page, const char *dest); - -/* Add a launch annotation (to a target of arbitrary file type). */ -PDFLIB_API void PDFLIB_CALL -PDF_add_launchlink(PDF *p, float llx, float lly, float urx, float ury, - const char *filename); - -/* Add a link annotation to a target within the current PDF file. */ -PDFLIB_API void PDFLIB_CALL -PDF_add_locallink(PDF *p, float llx, float lly, float urx, float ury, - int page, const char *dest); - -/* Add a weblink annotation to a target URL on the Web. */ -PDFLIB_API void PDFLIB_CALL -PDF_add_weblink(PDF *p, float llx, float lly, float urx, float ury, - const char *url); - -/* Set the border style for all kinds of annotations. style is "solid" or - "dashed". */ -PDFLIB_API void PDFLIB_CALL -PDF_set_border_style(PDF *p, const char *style, float width); - -/* Set the border color for all kinds of annotations. */ -PDFLIB_API void PDFLIB_CALL -PDF_set_border_color(PDF *p, float red, float green, float blue); - -/* Set the border dash style for all kinds of annotations. See PDF_setdash(). */ -PDFLIB_API void PDFLIB_CALL -PDF_set_border_dash(PDF *p, float b, float w); - - -/* - * ---------------------------------------------------------------------- - * p_pdi.c: PDF import (requires the PDI library) - * ---------------------------------------------------------------------- - */ - -/* Open an existing PDF document and prepare it for later use. */ -PDFLIB_API int PDFLIB_CALL -PDF_open_pdi(PDF *p, const char *filename, const char *stringparam, - int intparam); - -/* Close all open page handles, and close the input PDF document. */ -PDFLIB_API void PDFLIB_CALL -PDF_close_pdi(PDF *p, int doc); - -/* Prepare a page for later use with PDF_place_pdi_page(). */ -PDFLIB_API int PDFLIB_CALL -PDF_open_pdi_page(PDF *p, int doc, int page, const char *label); - -/* Place a PDF page with the lower left corner at (x, y), and scale it. */ -PDFLIB_API void PDFLIB_CALL -PDF_place_pdi_page(PDF *p, int page, float x, float y, float sx, float sy); - -/* Close the page handle, and free all page-related resources. */ -PDFLIB_API void PDFLIB_CALL -PDF_close_pdi_page(PDF *p, int page); - -/* Get the contents of some PDI document parameter with string type. */ -PDFLIB_API const char *PDFLIB_CALL -PDF_get_pdi_parameter(PDF *p, const char *key, int doc, int page, - int index, int *len); - -/* Get the contents of some PDI document parameter with numerical type. */ +/* Return the width of text in an arbitrary font. */ PDFLIB_API float PDFLIB_CALL -PDF_get_pdi_value(PDF *p, const char *key, int doc, int page, int index); +PDF_stringwidth(PDF *p, const char *text, int font, float fontsize); + +/* Same as PDF_stringwidth but with explicit string length. */ +PDFLIB_API float PDFLIB_CALL +PDF_stringwidth2(PDF *p, const char *text, int len, int font, float fontsize); +/* }}} */ + + +/* {{{ p_type3.c: Type 3 (user-defined) fonts + * ---------------------------------------------------------------------- + */ + +/* Start a type 3 font definition. */ +PDFLIB_API void PDFLIB_CALL +PDF_begin_font(PDF *p, const char *fontname, int reserved, + float a, float b, float c, float d, float e, float f, const char *optlist); + +/* Start a type 3 glyph definition. */ +PDFLIB_API void PDFLIB_CALL +PDF_begin_glyph(PDF *p, const char *glyphname, float wx, + float llx, float lly, float urx, float ury); + +/* Terminate a type 3 font definition. */ +PDFLIB_API void PDFLIB_CALL +PDF_end_font(PDF *p); + +/* Terminate a type 3 glyph definition. */ +PDFLIB_API void PDFLIB_CALL +PDF_end_glyph(PDF *p); +/* }}} */ + + +/* {{{ p_xgstate.c: explicit graphic states + * ---------------------------------------------------------------------- + */ + +/* Create a gstate object definition. */ +PDFLIB_API int PDFLIB_CALL +PDF_create_gstate(PDF *p, const char *optlist); + +/* Activate a gstate object. */ +PDFLIB_API void PDFLIB_CALL +PDF_set_gstate(PDF *p, int gstate); +/* }}} */ /* * ---------------------------------------------------------------------- - * p_stream.c: output stream handling + * PDFlib API structure with function pointers to all API functions * ---------------------------------------------------------------------- */ -/* Get the contents of the PDF output buffer. The result must be used by - the client before calling any other PDFlib function. */ -PDFLIB_API const char * PDFLIB_CALL -PDF_get_buffer(PDF *p, long *size); +/* The API structure with pointers to all PDFlib API functions */ +struct PDFlib_api_s { + /* {{{ p_annots.c: file attachments, notes, and links */ + void (PDFLIB_CALL * PDF_add_launchlink)(PDF *p, + float llx, float lly, float urx, + float ury, const char *filename); + void (PDFLIB_CALL * PDF_add_locallink)(PDF *p, + float llx, float lly, float urx, + float ury, int page, const char *optlist); + void (PDFLIB_CALL * PDF_add_note)(PDF *p, float llx, float lly, + float urx, float ury, const char *contents, const char *title, + const char *icon, int open); + void (PDFLIB_CALL * PDF_add_note2) (PDF *p, float llx, float lly, + float urx, float ury, const char *contents, int len_cont, + const char *title, int len_title, const char *icon, int open); + void (PDFLIB_CALL * PDF_add_pdflink)(PDF *p, + float llx, float lly, float urx, + float ury, const char *filename, int page, const char *optlist); + void (PDFLIB_CALL * PDF_add_weblink)(PDF *p, + float llx, float lly, float urx, float ury, const char *url); + void (PDFLIB_CALL * PDF_attach_file)(PDF *p, float llx, float lly, + float urx, float ury, const char *filename, + const char *description, + const char *author, const char *mimetype, const char *icon); + void (PDFLIB_CALL * PDF_attach_file2) (PDF *p, float llx, float lly, + float urx, float ury, const char *filename, int reserved, + const char *description, int len_descr, const char *author, + int len_auth, const char *mimetype, const char *icon); + void (PDFLIB_CALL * PDF_set_border_color)(PDF *p, + float red, float green, float blue); + void (PDFLIB_CALL * PDF_set_border_dash)(PDF *p, float b, float w); + void (PDFLIB_CALL * PDF_set_border_style)(PDF *p, + const char *style, float width); + /* }}} */ + + /* {{{ p_basic.c: general functions */ + void (PDFLIB_CALL * PDF_begin_page)(PDF *p, float width, + float height); + void (PDFLIB_CALL * PDF_boot)(void); + void (PDFLIB_CALL * PDF_close)(PDF *p); + void (PDFLIB_CALL * PDF_delete)(PDF *); + void (PDFLIB_CALL * PDF_end_page)(PDF *p); + const PDFlib_api * (PDFLIB_CALL * PDF_get_api)(void); + const char * (PDFLIB_CALL * PDF_get_buffer)(PDF *p, long *size); + int (PDFLIB_CALL * PDF_get_majorversion)(void); + int (PDFLIB_CALL * PDF_get_minorversion)(void); + void * (PDFLIB_CALL * PDF_get_opaque)(PDF *p); + PDF* (PDFLIB_CALL * PDF_new)(void); + PDF* (PDFLIB_CALL * PDF_new2)(errorproc_t errorhandler, + allocproc_t allocproc, + reallocproc_t reallocproc, + freeproc_t freeproc, void *opaque); + int (PDFLIB_CALL * PDF_open_file)(PDF *p, const char *filename); + int (PDFLIB_CALL * PDF_open_fp)(PDF *p, FILE *fp); + void (PDFLIB_CALL * PDF_open_mem)(PDF *p, writeproc_t writeproc); + void (PDFLIB_CALL * PDF_shutdown)(void); + /* }}} */ + + /* {{{ p_block.c: Variable Data Processing with blocks */ + int (PDFLIB_CALL * PDF_fill_imageblock) (PDF *p, int page, + const char *blockname, int image, const char *optlist); + int (PDFLIB_CALL * PDF_fill_pdfblock) (PDF *p, int page, + const char *blockname, int contents, const char *optlist); + int (PDFLIB_CALL * PDF_fill_textblock) (PDF *p, int page, + const char *blockname, const char *text, int len, + const char *optlist); + /* }}} */ + + /* {{{ p_color.c: color handling */ + int (PDFLIB_CALL * PDF_makespotcolor)(PDF *p, const char *spotname, + int reserved); + void (PDFLIB_CALL * PDF_setcolor)(PDF *p, + const char *fstype, const char *colorspace, + float c1, float c2, float c3, float c4); + void (PDFLIB_CALL * PDF_setgray)(PDF *p, float gray); + void (PDFLIB_CALL * PDF_setgray_stroke)(PDF *p, float gray); + void (PDFLIB_CALL * PDF_setgray_fill)(PDF *p, float gray); + void (PDFLIB_CALL * PDF_setrgbcolor)(PDF *p, float red, float green, + float blue); + void (PDFLIB_CALL * PDF_setrgbcolor_fill)(PDF *p, + float red, float green, float blue); + void (PDFLIB_CALL * PDF_setrgbcolor_stroke)(PDF *p, + float red, float green, float blue); + /* }}} */ + + /* {{{ p_draw.c: path construction, painting, and clipping */ + void (PDFLIB_CALL * PDF_arc)(PDF *p, float x, float y, + float r, float alpha, float beta); + void (PDFLIB_CALL * PDF_arcn)(PDF *p, float x, float y, + float r, float alpha, float beta); + void (PDFLIB_CALL * PDF_circle)(PDF *p, float x, float y, float r); + void (PDFLIB_CALL * PDF_clip)(PDF *p); + void (PDFLIB_CALL * PDF_closepath)(PDF *p); + void (PDFLIB_CALL * PDF_closepath_fill_stroke)(PDF *p); + void (PDFLIB_CALL * PDF_closepath_stroke)(PDF *p); + void (PDFLIB_CALL * PDF_curveto)(PDF *p, float x_1, float y_1, + float x_2, float y_2, float x_3, float y_3); + void (PDFLIB_CALL * PDF_endpath)(PDF *p); + void (PDFLIB_CALL * PDF_fill)(PDF *p); + void (PDFLIB_CALL * PDF_fill_stroke)(PDF *p); + void (PDFLIB_CALL * PDF_lineto)(PDF *p, float x, float y); + void (PDFLIB_CALL * PDF_moveto)(PDF *p, float x, float y); + void (PDFLIB_CALL * PDF_rect)(PDF *p, float x, float y, + float width, float height); + void (PDFLIB_CALL * PDF_stroke)(PDF *p); + /* }}} */ + + /* {{{ p_encoding.c: encoding handling */ + void (PDFLIB_CALL * PDF_encoding_set_char) (PDF *p, const char *encoding, + int slot, const char *glyphname, int uv); + /* }}} */ + + /* {{{ p_font.c: text and font handling */ + int (PDFLIB_CALL * PDF_findfont)(PDF *p, const char *fontname, + const char *encoding, int embed); + int (PDFLIB_CALL * PDF_load_font)(PDF *p, const char *fontname, + int reserved, const char *encoding, const char *optlist); + void (PDFLIB_CALL * PDF_setfont)(PDF *p, int font, float fontsize); + /* }}} */ + + /* {{{ p_gstate.c graphics state */ + void (PDFLIB_CALL * PDF_concat)(PDF *p, float a, float b, + float c, float d, float e, float f); + void (PDFLIB_CALL * PDF_initgraphics)(PDF *p); + void (PDFLIB_CALL * PDF_restore)(PDF *p); + void (PDFLIB_CALL * PDF_rotate)(PDF *p, float phi); + void (PDFLIB_CALL * PDF_save)(PDF *p); + void (PDFLIB_CALL * PDF_scale)(PDF *p, float sx, float sy); + void (PDFLIB_CALL * PDF_setdash)(PDF *p, float b, float w); + void (PDFLIB_CALL * PDF_setdashpattern) (PDF *p, const char *optlist); + void (PDFLIB_CALL * PDF_setflat)(PDF *p, float flatness); + void (PDFLIB_CALL * PDF_setlinecap)(PDF *p, int linecap); + void (PDFLIB_CALL * PDF_setlinejoin)(PDF *p, int linejoin); + void (PDFLIB_CALL * PDF_setlinewidth)(PDF *p, float width); + void (PDFLIB_CALL * PDF_setmatrix)(PDF *p, float a, float b, + float c, float d, float e, float f); + void (PDFLIB_CALL * PDF_setmiterlimit)(PDF *p, float miter); + void (PDFLIB_CALL * PDF_setpolydash)(PDF *p, float *dasharray, + int length); + void (PDFLIB_CALL * PDF_skew)(PDF *p, float alpha, float beta); + void (PDFLIB_CALL * PDF_translate)(PDF *p, float tx, float ty); + /* }}} */ + + /* {{{ p_hyper.c: bookmarks and document info fields */ + int (PDFLIB_CALL * PDF_add_bookmark)(PDF *p, const char *text, + int parent, int open); + int (PDFLIB_CALL * PDF_add_bookmark2) (PDF *p, const char *text, int len, + int parent, int open); + void (PDFLIB_CALL * PDF_add_nameddest) (PDF *p, const char *name, + int reserved, const char *optlist); + void (PDFLIB_CALL * PDF_set_info)(PDF *p, const char *key, + const char *value); + void (PDFLIB_CALL * PDF_set_info2) (PDF *p, const char *key, + const char *value, int len); + /* }}} */ + + /* {{{ p_icc.c: ICC profile handling */ + int (PDFLIB_CALL * PDF_load_iccprofile)(PDF *p, const char *profilename, + int reserved, const char *optlist); + /* }}} */ + + /* {{{ p_image.c: image handling */ + void (PDFLIB_CALL * PDF_add_thumbnail)(PDF *p, int image); + void (PDFLIB_CALL * PDF_close_image)(PDF *p, int image); + void (PDFLIB_CALL * PDF_fit_image) (PDF *p, int image, float x, float y, + const char *optlist); + int (PDFLIB_CALL * PDF_load_image) (PDF *p, const char *imagetype, + const char *filename, int reserved, const char *optlist); + int (PDFLIB_CALL * PDF_open_CCITT)(PDF *p, const char *filename, + int width, int height, + int BitReverse, int K, int BlackIs1); + int (PDFLIB_CALL * PDF_open_image)(PDF *p, const char *imagetype, + const char *source, const char *data, long length, int width, + int height, int components, int bpc, const char *params); + int (PDFLIB_CALL * PDF_open_image_file)(PDF *p, const char *imagetype, + const char *filename, const char *stringparam, int intparam); + void (PDFLIB_CALL * PDF_place_image)(PDF *p, int image, + float x, float y, float scale); + /* }}} */ + + /* {{{ p_kerning.c: font kerning */ + /* }}} */ + + /* {{{ p_params.c: parameter handling */ + const char* (PDFLIB_CALL * PDF_get_parameter)(PDF *p, + const char *key, float modifier); + float (PDFLIB_CALL * PDF_get_value)(PDF *p, const char *key, + float modifier); + void (PDFLIB_CALL * PDF_set_parameter)(PDF *p, + const char *key, const char *value); + void (PDFLIB_CALL * PDF_set_value)(PDF *p, const char *key, + float value); + /* }}} */ + + /* {{{ p_pattern.c: pattern definition */ + int (PDFLIB_CALL * PDF_begin_pattern)(PDF *p, + float width, float height, + float xstep, float ystep, int painttype); + void (PDFLIB_CALL * PDF_end_pattern)(PDF *p); + /* }}} */ + + /* {{{ p_pdi.c: PDF import (requires the PDI library) */ + void (PDFLIB_CALL * PDF_close_pdi)(PDF *p, int doc); + void (PDFLIB_CALL * PDF_close_pdi_page)(PDF *p, int page); + void (PDFLIB_CALL * PDF_fit_pdi_page) (PDF *p, int page, float x, + float y, const char *optlist); + const char * (PDFLIB_CALL * PDF_get_pdi_parameter)(PDF *p, + const char *key, int doc, int page, int idx, int *len); + float (PDFLIB_CALL * PDF_get_pdi_value)(PDF *p, const char *key, + int doc, int page, int idx); + int (PDFLIB_CALL * PDF_open_pdi)(PDF *p, const char *filename, + const char *optlist, int reserved); + int (PDFLIB_CALL * PDF_open_pdi_callback) (PDF *p, void *opaque, + size_t filesize, size_t (*readproc)(void *opaque, void *buffer, + size_t size), int (*seekproc)(void *opaque, long offset), + const char *optlist); + int (PDFLIB_CALL * PDF_open_pdi_page)(PDF *p, + int doc, int pagenumber, const char *optlist); + void (PDFLIB_CALL * PDF_place_pdi_page)(PDF *p, int page, + float x, float y, float sx, float sy); + int (PDFLIB_CALL * PDF_process_pdi)(PDF *p, + int doc, int page, const char *optlist); + /* }}} */ + + /* {{{ p_resource.c: resources and virtual file system handling */ + void (PDFLIB_CALL * PDF_create_pvf)(PDF *p, const char *filename, + int reserved, const void *data, size_t size, + const char *options); + int (PDFLIB_CALL * PDF_delete_pvf)(PDF *p, const char *filename, + int reserved); + /* }}} */ + + /* {{{ p_shading.c: shadings */ + int (PDFLIB_CALL * PDF_shading) (PDF *p, const char *shtype, float x_0, + float y_0, float x_1, float y_1, float c_1, float c_2, float c_3, + float c_4, const char *optlist); + int (PDFLIB_CALL * PDF_shading_pattern) (PDF *p, int shading, + const char *optlist); + void (PDFLIB_CALL * PDF_shfill) (PDF *p, int shading); + /* }}} */ + + /* {{{ p_template.c: template definition */ + int (PDFLIB_CALL * PDF_begin_template)(PDF *p, + float width, float height); + void (PDFLIB_CALL * PDF_end_template)(PDF *p); + /* }}} */ + + /* {{{ p_text.c: text output */ + void (PDFLIB_CALL * PDF_continue_text)(PDF *p, const char *text); + void (PDFLIB_CALL * PDF_continue_text2)(PDF *p, const char *text, + int len); + void (PDFLIB_CALL * PDF_fit_textline)(PDF *p, const char *text, + int len, float x, float y, const char *optlist); + void (PDFLIB_CALL * PDF_set_text_pos)(PDF *p, float x, float y); + void (PDFLIB_CALL * PDF_show)(PDF *p, const char *text); + void (PDFLIB_CALL * PDF_show2)(PDF *p, const char *text, int len); + int (PDFLIB_CALL * PDF_show_boxed)(PDF *p, const char *text, + float left, float top, float width, float height, + const char *hmode, const char *feature); + void (PDFLIB_CALL * PDF_show_xy)(PDF *p, const char *text, float x, + float y); + void (PDFLIB_CALL * PDF_show_xy2)(PDF *p, const char *text, + int len, float x, float y); + float (PDFLIB_CALL * PDF_stringwidth)(PDF *p, + const char *text, int font, float fontsize); + float (PDFLIB_CALL * PDF_stringwidth2)(PDF *p, const char *text, + int len, int font, float fontsize); + /* }}} */ + + /* {{{ p_type3.c: Type 3 (user-defined) fonts */ + void (PDFLIB_CALL * PDF_begin_font)(PDF *p, const char *fontname, + int reserved, float a, float b, float c, float d, float e, float f, + const char *optlist); + void (PDFLIB_CALL * PDF_begin_glyph)(PDF *p, const char *glyphname, + float wx, float llx, float lly, float urx, float ury); + void (PDFLIB_CALL * PDF_end_font)(PDF *p); + void (PDFLIB_CALL * PDF_end_glyph)(PDF *p); + /* }}} */ + + /* {{{ p_xgstate.c: explicit graphic states */ + int (PDFLIB_CALL * PDF_create_gstate) (PDF *p, const char *optlist); + void (PDFLIB_CALL * PDF_set_gstate) (PDF *p, int gstate); + /* }}} */ + + /* {{{ exception handling */ + int (PDFLIB_CALL * PDF_get_errnum) (PDF *p); + + const char * (PDFLIB_CALL * PDF_get_errmsg) (PDF *p); + + const char * (PDFLIB_CALL * PDF_get_apiname) (PDF *p); + /* }}} */ + + /* this is considered private */ + void *handle; +}; /* * ---------------------------------------------------------------------- @@ -696,19 +1159,6 @@ PDF_get_buffer(PDF *p, long *size); * ---------------------------------------------------------------------- */ -/* -Although PDF doesn´t impose any restrictions on the usable page size, -Acrobat implementations suffer from architectural limits concerning -the page size. -Although PDFlib will generate PDF documents with page sizes outside -these limits, the default error handler will issue a warning message. - -Acrobat 3 minimum page size: 1" = 72 pt = 2.54 cm -Acrobat 3 maximum page size: 45" = 3240 pt = 114.3 cm -Acrobat 4 minimum page size: 0.25" = 18 pt = 0.635 cm -Acrobat 4 maximum page size: 200" = 14400 pt = 508 cm -*/ - /* The page sizes are only available to the C and C++ bindings */ #define a0_width (float) 2380.0 #define a0_height (float) 3368.0 @@ -735,202 +1185,82 @@ Acrobat 4 maximum page size: 200" = 14400 pt = 508 cm #define p11x17_width (float) 792.0 #define p11x17_height (float) 1224.0 -/* The API structure with pointers to all PDFlib API functions */ -struct PDFlib_api_s { - /* general functions */ - PDFlib_api * (PDFLIB_CALL * const PDF_get_api)(void); - int (PDFLIB_CALL * const PDF_get_majorversion)(void); - int (PDFLIB_CALL * const PDF_get_minorversion)(void); - void (PDFLIB_CALL * const PDF_boot)(void); - void (PDFLIB_CALL * const PDF_shutdown)(void); - PDF* (PDFLIB_CALL * const PDF_new2)(errorproc_t errorhandler, - allocproc_t allocproc, - reallocproc_t reallocproc, - freeproc_t freeproc, void *opaque); - void * (PDFLIB_CALL * const PDF_get_opaque)(PDF *p); - PDF* (PDFLIB_CALL * const PDF_new)(void); - void (PDFLIB_CALL * const PDF_delete)(PDF *); - int (PDFLIB_CALL * const PDF_open_file)(PDF *p, const char *filename); - int (PDFLIB_CALL * const PDF_open_fp)(PDF *p, FILE *fp); - void (PDFLIB_CALL * const PDF_open_mem)(PDF *p, writeproc_t writeproc); - void (PDFLIB_CALL * const PDF_close)(PDF *p); - void (PDFLIB_CALL * const PDF_begin_page)(PDF *p, float width, - float height); - void (PDFLIB_CALL * const PDF_end_page)(PDF *p); - /* parameter handling */ - void (PDFLIB_CALL * const PDF_set_parameter)(PDF *p, - const char *key, const char *value); - void (PDFLIB_CALL * const PDF_set_value)(PDF *p, const char *key, - float value); - const char* (PDFLIB_CALL * const PDF_get_parameter)(PDF *p, - const char *key, float modifier); - float (PDFLIB_CALL * const PDF_get_value)(PDF *p, const char *key, - float modifier); +/* + * ---------------------------------------------------------------------- + * exception handling with try/catch implementation + * ---------------------------------------------------------------------- + */ - /* text and font handling */ - int (PDFLIB_CALL * const PDF_findfont)(PDF *p, const char *fontname, - const char *encoding, int embed); - void (PDFLIB_CALL * const PDF_setfont)(PDF *p, int font, float fontsize); - const char * (PDFLIB_CALL * const PDF_encoding_get_name)(PDF *p, - const char *encoding, int slot); +/* Set up an exception handling frame; must always be paired with PDF_CATCH().*/ - /* text output */ - void (PDFLIB_CALL * const PDF_show)(PDF *p, const char *text); - void (PDFLIB_CALL * const PDF_show_xy)(PDF *p, const char *text, float x, - float y); - void (PDFLIB_CALL * const PDF_continue_text)(PDF *p, const char *text); - int (PDFLIB_CALL * const PDF_show_boxed)(PDF *p, const char *text, - float left, float top, float width, float height, - const char *hmode, const char *feature); - void (PDFLIB_CALL * const PDF_set_text_matrix)(PDF *p, float a, float b, - float c, float d, float e, float f); - void (PDFLIB_CALL * const PDF_set_text_pos)(PDF *p, float x, float y); - float (PDFLIB_CALL * const PDF_stringwidth)(PDF *p, - const char *text, int font, float size); - void (PDFLIB_CALL * const PDF_show2)(PDF *p, const char *text, int len); - void (PDFLIB_CALL * const PDF_show_xy2)(PDF *p, const char *text, - int len, float x, float y); - void (PDFLIB_CALL * const PDF_continue_text2)(PDF *p, const char *text, - int len); - float (PDFLIB_CALL * const PDF_stringwidth2)(PDF *p, const char *text, - int len, int font, float size); - /* graphics state */ - void (PDFLIB_CALL * const PDF_setdash)(PDF *p, float b, float w); - void (PDFLIB_CALL * const PDF_setpolydash)(PDF *p, float *dasharray, - int length); - void (PDFLIB_CALL * const PDF_setflat)(PDF *p, float flatness); - void (PDFLIB_CALL * const PDF_setlinejoin)(PDF *p, int linejoin); - void (PDFLIB_CALL * const PDF_setlinecap)(PDF *p, int linecap); - void (PDFLIB_CALL * const PDF_setmiterlimit)(PDF *p, float miter); - void (PDFLIB_CALL * const PDF_setlinewidth)(PDF *p, float width); - void (PDFLIB_CALL * const PDF_initgraphics)(PDF *p); - void (PDFLIB_CALL * const PDF_save)(PDF *p); - void (PDFLIB_CALL * const PDF_restore)(PDF *p); - void (PDFLIB_CALL * const PDF_translate)(PDF *p, float tx, float ty); - void (PDFLIB_CALL * const PDF_scale)(PDF *p, float sx, float sy); - void (PDFLIB_CALL * const PDF_rotate)(PDF *p, float phi); - void (PDFLIB_CALL * const PDF_skew)(PDF *p, float alpha, float beta); - void (PDFLIB_CALL * const PDF_concat)(PDF *p, float a, float b, - float c, float d, float e, float f); - void (PDFLIB_CALL * const PDF_setmatrix)(PDF *p, float a, float b, - float c, float d, float e, float f); +#define PDF_TRY(pdf) if (pdf) { if (setjmp(pdf_jbuf(pdf)->jbuf) == 0) - /* path construction, painting, and clipping */ - void (PDFLIB_CALL * const PDF_moveto)(PDF *p, float x, float y); - void (PDFLIB_CALL * const PDF_lineto)(PDF *p, float x, float y); - void (PDFLIB_CALL * const PDF_curveto)(PDF *p, float x1, float y1, - float x2, float y2, float x3, float y3); - void (PDFLIB_CALL * const PDF_circle)(PDF *p, float x, float y, float r); - void (PDFLIB_CALL * const PDF_arc)(PDF *p, float x, float y, - float r, float alpha, float beta); - void (PDFLIB_CALL * const PDF_arcn)(PDF *p, float x, float y, - float r, float alpha, float beta); - void (PDFLIB_CALL * const PDF_rect)(PDF *p, float x, float y, - float width, float height); - void (PDFLIB_CALL * const PDF_closepath)(PDF *p); - void (PDFLIB_CALL * const PDF_stroke)(PDF *p); - void (PDFLIB_CALL * const PDF_closepath_stroke)(PDF *p); - void (PDFLIB_CALL * const PDF_fill)(PDF *p); - void (PDFLIB_CALL * const PDF_fill_stroke)(PDF *p); - void (PDFLIB_CALL * const PDF_closepath_fill_stroke)(PDF *p); - void (PDFLIB_CALL * const PDF_endpath)(PDF *p); - void (PDFLIB_CALL * const PDF_clip)(PDF *p); +/* Inform the exception machinery that a PDF_TRY() will be left without + entering the corresponding PDF_CATCH( ) clause. */ +#define PDF_EXIT_TRY(pdf) pdf_exit_try(pdf) - /* color handling */ - void (PDFLIB_CALL * const PDF_setgray_fill)(PDF *p, float gray); - void (PDFLIB_CALL * const PDF_setgray_stroke)(PDF *p, float gray); - void (PDFLIB_CALL * const PDF_setgray)(PDF *p, float gray); - void (PDFLIB_CALL * const PDF_setrgbcolor_fill)(PDF *p, - float red, float green, float blue); - void (PDFLIB_CALL * const PDF_setrgbcolor_stroke)(PDF *p, - float red, float green, float blue); - void (PDFLIB_CALL * const PDF_setrgbcolor)(PDF *p, float red, float green, - float blue); - int (PDFLIB_CALL * const PDF_makespotcolor)(PDF *p, const char *spotname, - int len); - void (PDFLIB_CALL * const PDF_setcolor)(PDF *p, - const char *fstype, const char *colorspace, - float c1, float c2, float c3, float c4); +/* Catch an exception; must always be paired with PDF_TRY(). */ +#define PDF_CATCH(pdf) } if (pdf_catch(pdf)) - /* pattern definition */ - int (PDFLIB_CALL * const PDF_begin_pattern)(PDF *p, - float width, float height, - float xstep, float ystep, int painttype); - void (PDFLIB_CALL * const PDF_end_pattern)(PDF *p); +/* Re-throw an exception to another handler. */ +#define PDF_RETHROW(pdf) pdf_rethrow(pdf) - /* template definition */ - int (PDFLIB_CALL * const PDF_begin_template)(PDF *p, - float width, float height); - void (PDFLIB_CALL * const PDF_end_template)(PDF *p); +/* Get the number of the last thrown exception. */ +PDFLIB_API int PDFLIB_CALL +PDF_get_errnum(PDF *p); - /* image handling */ - void (PDFLIB_CALL * const PDF_place_image)(PDF *p, int image, - float x, float y, float scale); - int (PDFLIB_CALL * const PDF_open_image)(PDF *p, const char *imagetype, - const char *source, const char *data, long length, int width, - int height, int components, int bpc, const char *params); - int (PDFLIB_CALL * const PDF_open_image_file)(PDF *p, const char *imagetype, - const char *filename, const char *stringparam, int intparam); - void (PDFLIB_CALL * const PDF_close_image)(PDF *p, int image); - void (PDFLIB_CALL * const PDF_add_thumbnail)(PDF *p, int image); +/* Get the descriptive text of the last thrown exception. */ +PDFLIB_API const char * PDFLIB_CALL +PDF_get_errmsg(PDF *p); - /* fax-compressed data processing */ - int (PDFLIB_CALL * const PDF_open_CCITT)(PDF *p, const char *filename, - int width, int height, - int BitReverse, int K, int BlackIs1); +/* Get the name of the API function which threw the last exception. */ +PDFLIB_API const char * PDFLIB_CALL +PDF_get_apiname(PDF *p); - /* bookmarks and document info fields */ - int (PDFLIB_CALL * const PDF_add_bookmark)(PDF *p, - const char *text, int parent, int open); - void (PDFLIB_CALL * const PDF_set_info)(PDF *p, - const char *key, const char *value); - /* file attachments, notes, and links */ - void (PDFLIB_CALL * const PDF_attach_file)(PDF *p, float llx, float lly, - float urx, float ury, const char *filename, - const char *description, - const char *author, const char *mimetype, const char *icon); - void (PDFLIB_CALL * const PDF_add_note)(PDF *p, float llx, float lly, - float urx, float ury, const char *contents, const char *title, - const char *icon, int open); - void (PDFLIB_CALL * const PDF_add_pdflink)(PDF *p, - float llx, float lly, float urx, - float ury, const char *filename, int page, const char *dest); - void (PDFLIB_CALL * const PDF_add_launchlink)(PDF *p, - float llx, float lly, float urx, - float ury, const char *filename); - void (PDFLIB_CALL * const PDF_add_locallink)(PDF *p, - float llx, float lly, float urx, - float ury, int page, const char *dest); - void (PDFLIB_CALL * const PDF_add_weblink)(PDF *p, - float llx, float lly, float urx, float ury, const char *url); - void (PDFLIB_CALL * const PDF_set_border_style)(PDF *p, - const char *style, float width); - void (PDFLIB_CALL * const PDF_set_border_color)(PDF *p, - float red, float green, float blue); - void (PDFLIB_CALL * const PDF_set_border_dash)(PDF *p, float b, float w); +/* + * ---------------------------------------------------------------------- + * End of public declarations + * ---------------------------------------------------------------------- + */ - /* PDF import (requires the PDI library) */ - int (PDFLIB_CALL * const PDF_open_pdi)(PDF *p, const char *filename, - const char *stringparam, int intparam); - void (PDFLIB_CALL * const PDF_close_pdi)(PDF *p, int doc); - int (PDFLIB_CALL * const PDF_open_pdi_page)(PDF *p, - int doc, int page, const char *label); - void (PDFLIB_CALL * const PDF_place_pdi_page)(PDF *p, int page, - float x, float y, float sx, float sy); - void (PDFLIB_CALL * const PDF_close_pdi_page)(PDF *p, int page); - const char * (PDFLIB_CALL * const PDF_get_pdi_parameter)(PDF *p, - const char *key, int doc, int page, int index, int *len); - float (PDFLIB_CALL * const PDF_get_pdi_value)(PDF *p, const char *key, - int doc, int page, int index); - /* output stream handling */ - const char * (PDFLIB_CALL * const PDF_get_buffer)(PDF *p, long *size); +/* + * ---------------------------------------------------------------------- + * Private stuff, do not use explicitly but only via the above macros! + * ---------------------------------------------------------------------- + */ + +#include + +typedef struct +{ + jmp_buf jbuf; +} pdf_jmpbuf; + +PDFLIB_API pdf_jmpbuf * PDFLIB_CALL +pdf_jbuf(PDF *p); + +PDFLIB_API void PDFLIB_CALL +pdf_exit_try(PDF *p); + +PDFLIB_API int PDFLIB_CALL +pdf_catch(PDF *p); + +PDFLIB_API void PDFLIB_CALL +pdf_rethrow(PDF *p); + +PDFLIB_API void PDFLIB_CALL +pdf_throw(PDF *p, const char *binding, const char *apiname, const char *errmsg); + + +/* + * ---------------------------------------------------------------------- + * End of useful stuff + * ---------------------------------------------------------------------- + */ - /* this is considered private */ - void *handle; -}; #ifdef __cplusplus } /* extern "C" */ @@ -941,3 +1271,7 @@ struct PDFlib_api_s { #endif #endif /* PDFLIB_H */ + +/* + * vim600: sw=4 fdm=marker + */