void CreateTextFunc::execute() { const int x0 = 0; const int y0 = 1; const int n = 2; int args[n]; ComValue& vect = stack_arg(0); ComValue& txtv = stack_arg(1); if (!vect.is_type(ComValue::ArrayType) || vect.array_len() != n) { reset_stack(); push_stack(ComValue::nullval()); return; } ALIterator i; AttributeValueList* avl = vect.array_val(); avl->First(i); for (int j=0; j<n && !avl->Done(i); j++) { args[j] = avl->GetAttrVal(i)->int_val(); avl->Next(i); } const char* txt = symbol_pntr( txtv.symbol_ref() ); AttributeList* al = stack_keys(); Resource::ref(al); reset_stack(); PasteCmd* cmd = nil; if (txt) { ColorVar* colVar = (ColorVar*) _ed->GetState("ColorVar"); FontVar* fntVar = (FontVar*) _ed->GetState("FontVar"); Transformer* rel = get_transformer(al); TextGraphic* text = new TextGraphic(txt, stdgraphic); if (colVar != nil) { text->FillBg(!colVar->GetBgColor()->None()); text->SetColors(colVar->GetFgColor(), colVar->GetBgColor()); } if (fntVar != nil) text->SetFont(fntVar->GetFont()); text->SetTransformer(new Transformer()); text->Translate(args[x0], args[y0]); text->GetTransformer()->postmultiply(rel); Unref(rel); TextOvComp* comp = new TextOvComp(text); comp->SetAttributeList(al); if (PasteModeFunc::paste_mode()==0) cmd = new PasteCmd(_ed, new Clipboard(comp)); ComValue compval(new OverlayViewRef(comp), symbol_add("TextComp")); push_stack(compval); execute_log(cmd); } else push_stack(ComValue::nullval()); Unref(al); }
Manipulator* TextOvView::CreateManipulator ( Viewer* v, Event& e, Transformer* rel, Tool* tool ) { Manipulator* m = nil; Editor* ed = v->GetEditor(); int tabWidth = Math::round(.5*ivinch); if (tool->IsA(GRAPHIC_COMP_TOOL)) { FontVar* fontVar = (FontVar*) ed->GetState("FontVar"); ColorVar* colVar = (ColorVar*) ed->GetState("ColorVar"); PSFont* font = (fontVar == nil) ? psstdfont : fontVar->GetFont(); PSColor* fg = (colVar == nil) ? psblack : colVar->GetFgColor(); int lineHt = font->GetLineHt(); Painter* painter = new Painter; painter->FillBg(false); painter->SetFont(font); painter->SetColors(fg, nil); Orientation o = v->GetOrientation(); if (o!=Rotated) painter->SetTransformer(rel); else { rel = new Transformer(rel); rel->Rotate(90.0); painter->SetTransformer(rel); Unref(rel); } m = new TextManip(v, painter, lineHt, tabWidth, tool); } else if (tool->IsA(RESHAPE_TOOL)) { TextGraphic* textgr = (TextGraphic*) GetGraphic(); Painter* painter = new Painter; int lineHt = textgr->GetLineHeight(); Coord xpos, ypos; rel = new Transformer; const char* text = textgr->GetOriginal(); int size = strlen(text); textgr->TotalTransformation(*rel); rel->Transform(0, 0, xpos, ypos); painter->FillBg(false); painter->SetFont(textgr->GetFont()); painter->SetColors(textgr->GetFgColor(), nil); painter->SetTransformer(rel); Unref(rel); m = new TextManip( v, text, size, xpos, ypos, painter, lineHt, tabWidth, tool ); } else { m = OverlayView::CreateManipulator(v, e, rel, tool); } return m; }
Command* StrBrowserView::InterpretManipulator (Manipulator* m) { Command* cmd = nil; Tool* tool = m->GetTool(); if (tool->IsA(IBGRAPHIC_COMP_TOOL)) { cmd = InteractorView::InterpretManipulator(m); } else if (tool->IsA(GRAPHIC_COMP_TOOL)) { DragManip* dm = (DragManip*) m; IBEditor* ed = (IBEditor*) dm->GetViewer()->GetEditor(); Tool* tool = dm->GetTool(); Transformer* rel = dm->GetTransformer(); RubberRect* rubberRect = (RubberRect*) dm->GetRubberband(); Coord x0, y0, x1, y1; rubberRect->GetCurrent(x0, y0, x1, y1); NormalRect(x0, y0, x1, y1); if (rel != nil) { rel->InvTransformRect(x0, y0, x1, y1); } GetABSCoord(ed, x0, y0, x1, y1); ColorVar* colVar = (ColorVar*) ed->GetState("ColorVar"); FontVar* fontVar = (FontVar*) ed->GetState("FontVar"); StrBrowserComp* comp = (StrBrowserComp*) GetStrBrowserComp()->Copy(); StrBrowserGraphic* g = (StrBrowserGraphic*) comp->GetGraphic(); g->SetRowsCols(y1-y0+1, x1-x0+1); if (colVar != nil) { g->SetColors(colVar->GetFgColor(), colVar->GetBgColor()); } if (fontVar != nil) { g->SetFont(fontVar->GetFont()); } cmd = new MacroCmd( ed, new PasteCmd(ed, new Clipboard(comp)), new PlaceCmd(ed, x0, y0, x1-1, y1-1, new Clipboard(comp)) ); } else if (!tool->IsA(RESHAPE_TOOL)){ cmd = MessageView::InterpretManipulator(m); } return cmd; }