boolean PostScriptViews::Emit (ostream& out) { SetPSFonts(); Graphic* g = GetGraphicComp()->GetGraphic(); Transformer* t = SaveTransformer(g); ScaleToPostScriptCoords(g); Comments(out); Prologue(out); Version(out); GridSpacing(out); out << "\n\n%%Page: 1 1\n\n"; out << "Begin\n"; FullGS(out); out << "/originalCTM matrix currentmatrix def\n\n"; boolean status = PreorderView::Definition(out); out << "End " << MARK << " eop\n\n"; out << "showpage\n\n"; Trailer(out); RestoreTransformer(g, t); return status; }
Command* PinView::InterpGraphicCompManip (Manipulator* m) { DragManip* dm = (DragManip*) m; Editor* ed = dm->GetViewer()->GetEditor(); BrushVar* brVar = (BrushVar*) ed->GetState("Brush"); SlidingPin* sp = (SlidingPin*) dm->GetRubberband(); Transformer* rel = dm->GetTransformer(); Coord px, py, dum; float dx, dy; PinGraphic* pinGraphic; sp->GetCurrent(px, py, dum, dum); if (rel != nil) { GetOffset(rel, px, py, dx, dy); rel = new Transformer; rel->Translate(dx, dy); } Graphic* pg = GetGraphicComp()->GetGraphic(); pinGraphic = new PinGraphic(px, py, pg); if (brVar != nil) pinGraphic->SetBrush(brVar->GetBrush()); pinGraphic->SetTransformer(rel); Unref(rel); return new PasteCmd(ed, new Clipboard(NewSubject(pinGraphic))); }
Command* PadView::InterpGraphicCompManip (Manipulator* m) { Command* cmd = nil; DragManip* dm = (DragManip*) m; SlidingRect* sr = (SlidingRect*) dm->GetRubberband(); Coord l, b, r, t; sr->GetCurrent(l, b, r, t); if (l != r || b != t) { DragManip* dm = (DragManip*) m; Editor* ed = dm->GetViewer()->GetEditor(); BrushVar* brVar = (BrushVar*) ed->GetState("Brush"); Transformer* rel = dm->GetTransformer(); if (rel != nil) { rel = new Transformer(rel); rel->Invert(); } Graphic* pg = GetGraphicComp()->GetGraphic(); PadGraphic* padGraphic = new PadGraphic(l, b, r, t, pg); if (brVar != nil) padGraphic->SetBrush(brVar->GetBrush()); padGraphic->SetTransformer(rel); Unref(rel); cmd = new PasteCmd(ed, new Clipboard(NewSubject(padGraphic))); } return cmd; }
void PostScriptView::Brush (ostream& out) { PSBrush* brush = (PSBrush*) GetGraphicComp()->GetGraphic()->GetBrush(); if (brush == nil) { out << MARK << " b u\n"; } else if (brush->None()) { out << "none SetB " << MARK << " b n\n"; } else { int p = brush->GetLinePattern(); out << MARK << " b " << p << "\n"; float w = brush->width(); out << w << " " << false << " " << false << " "; const int* dashpat = brush->GetDashPattern(); int dashpatsize = brush->GetDashPatternSize(); int dashoffset = brush->GetDashOffset(); if (dashpatsize <= 0) { out << "[] " << dashoffset << " "; } else { out << "["; int i; for (i = 0; i < dashpatsize - 1; i++) { out << dashpat[i] << " "; } out << dashpat[i] << "] " << dashoffset << " "; } out << "SetB\n"; } }
void NewViewCmd::Execute () { Editor* ed = GetEditor(); Editor* newEd = new IdrawEditor(GetGraphicComp()); *newEd->GetState("ModifStatusVar") = *ed->GetState("ModifStatusVar"); unidraw->Open(newEd); }
UList* PostScriptView::GetPSFonts () { if (_fonts == nil) { _fonts = new UList; CollectFonts(GetGraphicComp(), _fonts); } return _fonts; }
Command* TextOvView::InterpretManipulator (Manipulator* m) { Viewer* v = m->GetViewer(); Editor* ed = v->GetEditor(); Tool* tool = m->GetTool(); Command* cmd = nil; if (tool->IsA(GRAPHIC_COMP_TOOL) || tool->IsA(RESHAPE_TOOL)) { TextManip* tm = (TextManip*) m; int size; const char* text = tm->GetText(size); if (size == 0) { if (tool->IsA(RESHAPE_TOOL)) { cmd = new OvDeleteCmd(ed); } else { v->Update(); // to repair text display-incurred damage } } else { Coord xpos, ypos; tm->GetPosition(xpos, ypos); Painter* p = tm->GetPainter(); Transformer* rel = tm->GetPainter()->GetTransformer(); int lineHt = tm->GetLineHeight(); Graphic* pg = GetGraphicComp()->GetGraphic(); TextGraphic* textgr = new TextGraphic(text, lineHt, pg); if (tool->IsA(GRAPHIC_COMP_TOOL)) { textgr->SetTransformer(nil); } if (rel != nil) { if (v->GetOrientation()==Rotated && !tool->IsA(RESHAPE_TOOL)) rel->Rotate(-90); rel->InvTransform(xpos, ypos); } if (v->GetOrientation()==Rotated && !tool->IsA(RESHAPE_TOOL)) textgr->Rotate(90.0); textgr->Translate(xpos, ypos); textgr->FillBg(false); textgr->SetFont((PSFont*) p->GetFont()); textgr->SetColors((PSColor*) p->GetFgColor(), nil); if (tool->IsA(GRAPHIC_COMP_TOOL)) { cmd = new PasteCmd(ed, new Clipboard(new TextOvComp(textgr))); } else { cmd = new ReplaceCmd(ed, new TextOvComp(textgr)); } } } else { cmd = OverlayView::InterpretManipulator(m); } return cmd; }
Graphic* BitmapView::GetGraphic () { Graphic* g = GraphicView::GetGraphic(); if (g == nil) { g = GetGraphicComp()->GetGraphic()->Copy(); SetGraphic(g); } return g; }
void PostScriptView::Font (ostream& out) { PSFont* font = (PSFont*) GetGraphicComp()->GetGraphic()->GetFont(); if (font == nil) { out << MARK << " f u\n"; } else { const char* name = font->GetName(); const char* pf = font->GetPrintFont(); const char* ps = font->GetPrintSize(); out << MARK << " f " << name << "\n"; out << pf << " " << ps << " SetF\n"; } }
void PostScriptView::Transformation (ostream& out) { Transformer* t = GetGraphicComp()->GetGraphic()->GetTransformer(); Transformer identity; if (t == nil || *t == identity) { out << MARK << " t u\n"; } else { float a00, a01, a10, a11, a20, a21; t->GetEntries(a00, a01, a10, a11, a20, a21); out << MARK << " t\n"; out << "[ " << a00 << " " << a01 << " " << a10 << " "; out << a11 << " " << a20 << " " << a21 << " ] concat\n"; } }
void PostScriptViews::Update () { DeleteViews(); GraphicComp* comps = GetGraphicComp(); Iterator i; for (comps->First(i); !comps->Done(i); comps->Next(i)) { GraphicComp* comp = comps->GetComp(i); PostScriptView* psv = CreatePSView(comp); if (psv != nil) { _views->Append(new UList(psv)); } } }
void PrintCmd::Execute () { GraphicComp* comps = GetGraphicComp(); boolean ok; if (_dialog == nil) { _dialog = new PrintDialog; } do { _editor->InsertDialog(_dialog); boolean accepted = _dialog->Accept(); _editor->RemoveDialog(_dialog); if (!accepted) { break; } filebuf fbuf; char* tmpfilename; if (_dialog->ToPrinter()) { tmpfilename = tmpnam(nil); ok = fbuf.open(tmpfilename, IOS_OUT) != 0; } else { ok = fbuf.open((char*) _dialog->Choice(), IOS_OUT) != 0; } if (ok) { ostream out(&fbuf); ExternView* ev = (ExternView*) comps->Create(POSTSCRIPT_VIEW); comps->Attach(ev); ev->Update(); ok = ev->Emit(out); out.flush(); delete ev; if (_dialog->ToPrinter()) { ok = print(_dialog->Choice(), tmpfilename) == 0; } } if (!ok) { _dialog->SetTitle("Couldn't print!"); } } while (!ok); _dialog->SetTitle(""); }
void PostScriptView::BgColor (ostream& out) { PSColor* bgcolor = (PSColor*) GetGraphicComp()->GetGraphic()->GetBgColor(); if (bgcolor == nil) { out << MARK << " cbg u\n"; } else { const char* name = bgcolor->GetName(); out << MARK << " cbg " << name << "\n"; if (strcmp(name, "white") == 0 || strcmp(name, "White") == 0) { out << "1 1 1 SetCBg\n"; } else { ColorIntensity r, g, b; bgcolor->GetIntensities(r, g, b); out << r << " " << g << " " << b << " SetCBg\n"; } } }
Command* EllipseView::InterpretManipulator (Manipulator* m) { DragManip* dm = (DragManip*) m; Editor* ed = dm->GetViewer()->GetEditor(); Tool* tool = dm->GetTool(); Transformer* rel = dm->GetTransformer(); Command* cmd = nil; if (tool->IsA(GRAPHIC_COMP_TOOL)) { RubberEllipse* re = (RubberEllipse*) dm->GetRubberband(); Coord x, y, dummy1, dummy2; re->GetCurrent(x, y, dummy1, dummy2); if (dummy1 != x || dummy2 != y) { BrushVar* brVar = (BrushVar*) ed->GetState("BrushVar"); PatternVar* patVar = (PatternVar*) ed->GetState("PatternVar"); ColorVar* colVar = (ColorVar*) ed->GetState("ColorVar"); Coord xr, yr; re->CurrentRadii(xr, yr); if (rel != nil) { rel = new Transformer(rel); rel->Invert(); } Graphic* pg = GetGraphicComp()->GetGraphic(); SF_Ellipse* ellipse = new SF_Ellipse(x, y, xr, yr, pg); if (brVar != nil) ellipse->SetBrush(brVar->GetBrush()); if (patVar != nil) ellipse->SetPattern(patVar->GetPattern()); if (colVar != nil) { ellipse->SetColors(colVar->GetFgColor(), colVar->GetBgColor()); } ellipse->SetTransformer(rel); Unref(rel); cmd = new PasteCmd(ed, new Clipboard(new EllipseComp(ellipse))); } } else { cmd = GraphicView::InterpretManipulator(m); } return cmd; }
boolean TextPS::Definition (ostream& out) { TextGraphic* g = (TextGraphic*) GetGraphicComp()->GetGraphic(); const char* text = g->GetOriginal(); int count = strlen(text); out << "Begin " << MARK << " Text\n"; float sep = g->GetLineHeight() - 1; // correct for vert shift Transformer corrected, *t = g->GetTransformer(); corrected.Translate(0., sep); if (t == nil) { g->SetTransformer(&corrected); TextGS(out); g->SetTransformer(t); } else { t->Reference(); corrected.Postmultiply(t); g->SetTransformer(&corrected); TextGS(out); g->SetTransformer(t); Unref(t); } out << MARK << "\n"; out << "[\n"; int beg, end, lineSize, nextBeg, ypos = 0; for (beg = 0; beg < count; beg = nextBeg) { GetLine(text, count, beg, end, lineSize, nextBeg); const char* string = Filter(&text[beg], end - beg + 1); out << "(" << string << ")\n"; } out << "] Text\n"; out << "End\n\n"; return out.good(); }
void PostScriptView::Pattern (ostream& out) { PSPattern* pat = (PSPattern*) GetGraphicComp()->GetGraphic()->GetPattern(); if (pat == nil) { out << MARK << " p u\n"; } else if (pat->None()) { out << "none SetP " << MARK << " p n\n"; } else if (pat->GetSize() > 0) { const int* data = pat->GetData(); int size = pat->GetSize(); char buf[CHARBUFSIZE]; out << MARK << " p\n"; out << "< "; if (size <= 8) { for (int i = 0; i < 8; i++) { sprintf(buf, "%02x", data[i] & 0xff); out << buf << " "; } } else { for (int i = 0; i < patternHeight; i++) { sprintf(buf, "%0*x", patternWidth/4, data[i]); if (i != patternHeight - 2) { out << buf << " "; } else { out << buf << "\n "; } } } out << "> -1 SetP\n"; } else { float graylevel = pat->GetGrayLevel(); out << MARK << " p\n"; out << graylevel << " SetP\n"; } }
Command* LinkView::InterpLinkCompManip (Manipulator* m) { Viewer* v = m->GetViewer(); Editor* ed = v->GetEditor(); GraphicView* views = v->GetGraphicView(); BrushVar* brVar = (BrushVar*) ed->GetState("BrushVar"); ConnectManip* cm = (ConnectManip*) m; Transformer* rel = cm->GetTransformer(); RubberGroup* rg = (RubberGroup*) cm->GetRubberband(); RubberLine* rl = (RubberLine*) rg->First(); Coord x0, y0, x1, y1; Connector* c1, *c2; ConnectorView* target1, *target2; MacroCmd* macro = new MacroCmd(ed); rl->GetCurrent(x0, y0, x1, y1); if (rel != nil) { rel = new Transformer(rel); rel->Invert(); } Graphic* pg = GetGraphicComp()->GetGraphic(); Line* line = new Line(x0, y0, x1, y1, pg); if (brVar != nil) line->SetBrush(brVar->GetBrush()); line->SetTransformer(rel); Unref(rel); LinkComp* linkComp = NewSubject(line); linkComp->GetConnectors(c1, c2); macro->Append(new PasteCmd(ed, new Clipboard(linkComp))); target1 = views->ConnectorIntersecting(x0-SLOP, y0-SLOP, x0+SLOP, y0+SLOP); target2 = views->ConnectorIntersecting(x1-SLOP, y1-SLOP, x1+SLOP, y1+SLOP); if (target1 != nil) { macro->Append(new ConnectCmd(ed, c1, target1->GetConnector())); } if (target2 != nil) { macro->Append(new ConnectCmd(ed, c2, target2->GetConnector())); } return macro; }
void PSArrowLine::Brush (ostream& out) { ArrowLineComp* comp = (ArrowLineComp*) GetSubject(); PSBrush* brush = (PSBrush*) GetGraphicComp()->GetGraphic()->GetBrush(); boolean head, tail; head = comp->GetArrowLine()->Head(); tail = comp->GetArrowLine()->Tail(); if (brush == nil) { out << MARK << " b u\n"; } else if (brush->None()) { out << "none SetB " << MARK << " b n\n"; } else { int p = brush->GetLinePattern(); out << MARK << " b " << p << "\n"; int w = brush->Width(); out << w << " " << head << " " << tail << " "; const int* dashpat = brush->GetDashPattern(); int dashpatsize = brush->GetDashPatternSize(); int dashoffset = brush->GetDashOffset(); if (dashpatsize <= 0) { out << "[] " << dashoffset << " "; } else { out << "["; for (int i = 0; i < dashpatsize - 1; i++) { out << dashpat[i] << " "; } out << dashpat[i] << "] " << dashoffset << " "; } out << "SetB\n"; } }
void PostScriptView::GetBox (Coord& l, Coord& b, Coord& r, Coord& t) { GetGraphicComp()->GetGraphic()->GetBox(l, b, r, t); }
Command* RectView::InterpretManipulator (Manipulator* m) { DragManip* dm = (DragManip*) m; Editor* ed = dm->GetViewer()->GetEditor(); Tool* tool = dm->GetTool(); Transformer* rel = dm->GetTransformer(); Command* cmd = nil; if (tool->IsA(GRAPHIC_COMP_TOOL)) { RubberRect* rr = (RubberRect*) dm->GetRubberband(); Coord x0, y0, x1, y1; rr->GetCurrent(x0, y0, x1, y1); if (x0 != x1 || y0 != y1) { BrushVar* brVar = (BrushVar*) ed->GetState("BrushVar"); PatternVar* patVar = (PatternVar*) ed->GetState("PatternVar"); ColorVar* colVar = (ColorVar*) ed->GetState("ColorVar"); if (rel != nil) { rel = new Transformer(rel); rel->Invert(); } Graphic* pg = GetGraphicComp()->GetGraphic(); SF_Rect* rect = new SF_Rect(x0, y0, x1, y1, pg); if (brVar != nil) rect->SetBrush(brVar->GetBrush()); if (patVar != nil) rect->SetPattern(patVar->GetPattern()); if (colVar != nil) { rect->SetColors(colVar->GetFgColor(), colVar->GetBgColor()); } rect->SetTransformer(rel); Unref(rel); cmd = new PasteCmd(ed, new Clipboard(new RectComp(rect))); } } else if (tool->IsA(RESHAPE_TOOL)) { RubberGroup* rubberGroup = (RubberGroup*) dm->GetRubberband(); RubberLine* rubberLine = (RubberLine*) rubberGroup->First(); SF_Polygon* polygon; Coord x[4], y[4]; Coord x0, y0; GetCorners(x, y); rubberLine->GetCurrent(x0, y0, x[_reshapeCorner], y[_reshapeCorner]); if (rel != nil) { rel = new Transformer(rel); rel->Invert(); } polygon = new SF_Polygon(x, y, 4, GetGraphic()); polygon->SetTransformer(rel); Unref(rel); cmd = new ReplaceCmd(ed, new PolygonComp(polygon)); } else if (tool->IsA(MOVE_TOOL)) { SlidingLineList* sll; Transformer* rel = dm->GetTransformer(); Coord* ox, *oy, *cx, *cy; float fx0, fy0, fx1, fy1; int n; sll = (SlidingLineList*) dm->GetRubberband(); sll->GetOriginal(ox, oy, n); sll->GetCurrent(cx, cy, n); if (rel != nil) { rel->InvTransform(float(ox[0]), float(oy[0]), fx0, fy0); rel->InvTransform(float(cx[0]), float(cy[0]), fx1, fy1); } delete ox; delete oy; delete cx; delete cy; cmd = new MoveCmd(ed, fx1 - fx0, fy1 - fy0); } else if (tool->IsA(SCALE_TOOL)) { ScalingLineList* sll = (ScalingLineList*) dm->GetRubberband(); float sxy = sll->CurrentScaling(); cmd = new ScaleCmd(ed, sxy, sxy); } else if (tool->IsA(ROTATE_TOOL)) { RotatingLineList* rll = (RotatingLineList*) dm->GetRubberband(); float angle = rll->CurrentAngle() - rll->OriginalAngle(); cmd = new RotateCmd(ed, angle); } else { cmd = GraphicView::InterpretManipulator(m); } return cmd; }
Command* LineView::InterpretManipulator (Manipulator* m) { DragManip* dm = (DragManip*) m; Editor* ed = dm->GetViewer()->GetEditor(); Tool* tool = dm->GetTool(); Transformer* rel = dm->GetTransformer(); Command* cmd = nil; if (tool->IsA(GRAPHIC_COMP_TOOL)) { RubberLine* rl = (RubberLine*) dm->GetRubberband(); Coord x0, y0, x1, y1; rl->GetCurrent(x0, y0, x1, y1); if (x0 != x1 || y0 != y1) { BrushVar* brVar = (BrushVar*) ed->GetState("BrushVar"); ColorVar* colVar = (ColorVar*) ed->GetState("ColorVar"); if (rel != nil) { rel = new Transformer(rel); rel->Invert(); } Graphic* pg = GetGraphicComp()->GetGraphic(); Line* line = new Line(x0, y0, x1, y1, pg); if (brVar != nil) line->SetBrush(brVar->GetBrush()); if (colVar != nil) { line->SetColors(colVar->GetFgColor(), colVar->GetBgColor()); } line->SetTransformer(rel); Unref(rel); cmd = new PasteCmd(ed, new Clipboard(new LineComp(line))); } } else if (tool->IsA(MOVE_TOOL)) { Coord x0, y0, x1, y1, dummy1, dummy2; float fx0, fy0, fx1, fy1; SlidingLine* sl = (SlidingLine*) dm->GetRubberband(); sl->GetOriginal(x0, y0, dummy1, dummy2); sl->GetCurrent(x1, y1, dummy1, dummy2); if (rel != nil) { rel->InvTransform(float(x0), float(y0), fx0, fy0); rel->InvTransform(float(x1), float(y1), fx1, fy1); } cmd = new MoveCmd(ed, fx1 - fx0, fy1 - fy0); } else if (tool->IsA(SCALE_TOOL)) { ScalingLine* sl = (ScalingLine*) dm->GetRubberband(); float sxy = sl->CurrentScaling(); cmd = new ScaleCmd(ed, sxy, sxy); } else if (tool->IsA(ROTATE_TOOL)) { RotatingLine* rl = (RotatingLine*) dm->GetRubberband(); float angle = rl->CurrentAngle() - rl->OriginalAngle(); cmd = new RotateCmd(ed, angle); } else if (tool->IsA(RESHAPE_TOOL)) { RubberLine* rl = (RubberLine*) dm->GetRubberband(); Coord x0, y0, x1, y1; rl->GetCurrent(x0, y0, x1, y1); if (rel != nil) { rel = new Transformer(rel); rel->Invert(); } Line* line = new Line(x0, y0, x1, y1, GetGraphic()); line->SetTransformer(rel); Unref(rel); cmd = new ReplaceCmd(ed, new LineComp(line)); } else { cmd = GraphicView::InterpretManipulator(m); } return cmd; }
Command* MultiLineView::InterpretManipulator (Manipulator* m) { DragManip* dm = (DragManip*) m; Editor* ed = dm->GetViewer()->GetEditor(); Tool* tool = dm->GetTool(); Transformer* rel = dm->GetTransformer(); Command* cmd = nil; if (tool->IsA(GRAPHIC_COMP_TOOL)) { GrowingVertices* gv = (GrowingVertices*) dm->GetRubberband(); Coord* x, *y; int n, pt; gv->GetCurrent(x, y, n, pt); if (n > 2 || x[0] != x[1] || y[0] != y[1]) { BrushVar* brVar = (BrushVar*) ed->GetState("BrushVar"); PatternVar* patVar = (PatternVar*) ed->GetState("PatternVar"); ColorVar* colVar = (ColorVar*) ed->GetState("ColorVar"); if (rel != nil) { rel = new Transformer(rel); rel->Invert(); } Graphic* pg = GetGraphicComp()->GetGraphic(); SF_MultiLine* polygon = new SF_MultiLine(x, y, n, pg); if (brVar != nil) polygon->SetBrush(brVar->GetBrush()); if (patVar != nil) polygon->SetPattern(patVar->GetPattern()); if (colVar != nil) { polygon->SetColors(colVar->GetFgColor(), colVar->GetBgColor()); } polygon->SetTransformer(rel); Unref(rel); cmd = new PasteCmd(ed, new Clipboard(new MultiLineComp(polygon))); } delete x; delete y; } else if (tool->IsA(RESHAPE_TOOL)) { GrowingVertices* gv = (GrowingVertices*) dm->GetRubberband(); Coord* x, *y; int n, pt; gv->RemoveVertex(); gv->GetCurrent(x, y, n, pt); if (rel != nil) { rel = new Transformer(rel); rel->Invert(); } SF_MultiLine* polygon = new SF_MultiLine(x, y, n, GetGraphic()); delete x; delete y; polygon->SetTransformer(rel); Unref(rel); cmd = new ReplaceCmd(ed, new MultiLineComp(polygon)); } else { cmd = VerticesView::InterpretManipulator(m); } return cmd; }