- 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
This commit is contained in:
parent
626824eaaf
commit
ceffc48db9
@ -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 {
|
||||
|
@ -39,6 +39,7 @@ THE SOFTWARE.
|
||||
#include <FindDirectory.h>
|
||||
#include <Path.h>
|
||||
#include <String.h>
|
||||
#include "InterfaceUtils.h"
|
||||
#include "Utils.h"
|
||||
#include "PrinterDriver.h"
|
||||
|
||||
@ -73,6 +74,7 @@ private:
|
||||
|
||||
BMessage* fSettings;
|
||||
|
||||
BTextControl* fLicenseKey;
|
||||
bool fCreateLinks;
|
||||
float fLinkBorderWidth;
|
||||
bool fCreateBookmarks;
|
||||
|
@ -30,210 +30,53 @@ THE SOFTWARE.
|
||||
#include <InterfaceKit.h>
|
||||
#include <SupportKit.h>
|
||||
#include "DocInfoWindow.h"
|
||||
#include "InterfaceUtils.h"
|
||||
#include <ctype.h>
|
||||
|
||||
|
||||
// --------------------------------------------------
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------
|
||||
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());
|
||||
Permissions::Permissions() {
|
||||
fNofPermissions = sizeof(gPermissionLabels)/sizeof(PermissionLabels);
|
||||
fPermissions = new Permission[fNofPermissions];
|
||||
for (int i = 0; i < fNofPermissions; i ++) {
|
||||
fPermissions[i].SetLabels(&gPermissionLabels[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------
|
||||
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<TextControl*>(parent);
|
||||
if (control) control->FocusSetTo(this);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------
|
||||
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<BScrollView*>(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,17 +86,79 @@ 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,
|
||||
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);
|
||||
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");
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -39,8 +39,52 @@ THE SOFTWARE.
|
||||
#include <FindDirectory.h>
|
||||
#include <Path.h>
|
||||
#include <String.h>
|
||||
#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);
|
||||
|
@ -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();
|
||||
|
@ -31,35 +31,11 @@ THE SOFTWARE.
|
||||
|
||||
#include <InterfaceKit.h>
|
||||
#include <SupportKit.h>
|
||||
#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;
|
||||
|
283
src/add-ons/print/drivers/pdf/source/InterfaceUtils.cpp
Normal file
283
src/add-ons/print/drivers/pdf/source/InterfaceUtils.cpp
Normal file
@ -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 <string.h>
|
||||
#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<TextControl*>(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<BScrollView*>(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;
|
||||
}
|
||||
|
||||
|
||||
|
117
src/add-ons/print/drivers/pdf/source/InterfaceUtils.h
Normal file
117
src/add-ons/print/drivers/pdf/source/InterfaceUtils.h
Normal file
@ -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 <InterfaceKit.h>
|
||||
|
||||
// --------------------------------------------------
|
||||
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
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,7 @@ THE SOFTWARE.
|
||||
#define JOBSETUPWINDOW_H
|
||||
|
||||
#include <InterfaceKit.h>
|
||||
#include "InterfaceUtils.h"
|
||||
#include "Utils.h"
|
||||
|
||||
class JobSetupWindow : public HWindow
|
||||
|
@ -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);
|
||||
};
|
||||
|
||||
|
@ -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()) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
PDF_set_parameter(fPdf, "flush", "heavy");
|
||||
// pdflib scope:
|
||||
|
||||
PDF_set_parameter(fPdf, "flush", "content");
|
||||
|
||||
// set document info
|
||||
BMessage doc;
|
||||
@ -370,9 +407,6 @@ PDFWriter::InitWriter()
|
||||
}
|
||||
}
|
||||
|
||||
fState = NULL;
|
||||
fStateDepth = 0;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@ -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 ||
|
||||
@ -552,6 +668,7 @@ PDFWriter::SetColor(rgb_color color)
|
||||
float green = color.green / 255.0;
|
||||
float blue = color.blue / 255.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();
|
||||
}
|
||||
|
||||
|
||||
@ -1508,46 +1745,50 @@ PDFWriter::PaintRoundRect(BRect rect, BPoint radii, bool stroke) {
|
||||
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;
|
||||
float ay = sy;
|
||||
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,8 +2088,9 @@ 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 {
|
||||
@ -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;
|
||||
|
@ -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:
|
||||
@ -272,6 +283,24 @@ class PDFWriter : public PrinterDriver, public PictureIterator
|
||||
};
|
||||
};
|
||||
|
||||
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<Font> fFontCache;
|
||||
TList<Pattern> fPatterns;
|
||||
TList<Transparency> fTransparencyCache;
|
||||
TList<Transparency> fTransparencyStack;
|
||||
int64 fEmbedMaxFontSize;
|
||||
BScreen *fScreen;
|
||||
Fonts *fFonts;
|
||||
@ -315,6 +346,10 @@ 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; }
|
||||
@ -325,6 +360,11 @@ class PDFWriter : public PrinterDriver, public PictureIterator
|
||||
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();
|
||||
|
||||
|
@ -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);
|
||||
|
@ -39,6 +39,7 @@ THE SOFTWARE.
|
||||
#include <FindDirectory.h>
|
||||
#include <Path.h>
|
||||
#include <String.h>
|
||||
#include "InterfaceUtils.h"
|
||||
#include "Utils.h"
|
||||
#include "Fonts.h"
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -33,6 +33,7 @@ THE SOFTWARE.
|
||||
#define PRINTERSETUPWINDOW_H
|
||||
|
||||
#include <InterfaceKit.h>
|
||||
#include "InterfaceUtils.h"
|
||||
#include "Utils.h"
|
||||
|
||||
class PrinterSetupWindow : public HWindow
|
||||
|
@ -31,6 +31,8 @@ THE SOFTWARE.
|
||||
#include <string.h>
|
||||
#include <Autolock.h>
|
||||
|
||||
#define LOGGING 0
|
||||
|
||||
Report* Report::fInstance = NULL;
|
||||
|
||||
|
||||
|
@ -36,6 +36,7 @@ THE SOFTWARE.
|
||||
|
||||
//class PrinterDriver;
|
||||
#include "PrinterDriver.h"
|
||||
#include "InterfaceUtils.h"
|
||||
#include "Utils.h"
|
||||
|
||||
class StatusWindow : public HWindow
|
||||
|
@ -30,10 +30,6 @@ THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "Utils.h"
|
||||
#include <Window.h>
|
||||
#include <Alert.h>
|
||||
#include <TextView.h>
|
||||
#include <string.h>
|
||||
|
||||
// --------------------------------------------------
|
||||
EscapeMessageFilter::EscapeMessageFilter(BWindow *window, int32 what)
|
||||
@ -57,82 +53,52 @@ EscapeMessageFilter::Filter(BMessage *msg, BHandler **target)
|
||||
return B_DISPATCH_MESSAGE;
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------
|
||||
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);
|
||||
// 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 <stdio.h>
|
||||
|
||||
// --------------------------------------------------
|
||||
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);
|
||||
}
|
||||
// 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);
|
||||
|
||||
|
||||
// --------------------------------------------------
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -37,6 +37,10 @@ THE SOFTWARE.
|
||||
#include <MessageFilter.h>
|
||||
|
||||
|
||||
// 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<T>::AddItem(T* p) {
|
||||
fList.AddItem(p);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T* TList<T>::RemoveItem(int i) {
|
||||
return (T*)fList.RemoveItem(i);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
T* TList<T>::Items() {
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user