int TextFileScript::ReadTextFile (istream& in, void* addr1, void* addr2, void* addr3, void* addr4) { int line_height; char delim; char pathname[BUFSIZ]; TextFileComp* textfilecomp = (TextFileComp*)addr1; in >> line_height; ParamList::skip_space(in); in >> delim; if (delim == ',' && in.good()) { ParamList::skip_space(in); if (ParamList::parse_pathname(in, pathname, BUFSIZ, textfilecomp->GetBaseDir()) != 0) return -1; } if (!in.good()) { return -1; } else { textfilecomp->_pathname = strdup(pathname); TextGraphic* tg = new TextGraphic("", line_height); tg->SetFont(psstdfont); tg->SetColors(psblack, nil); tg->FillBg(false); textfilecomp->SetGraphic(tg); return 0; } }
TextGraphic* TextFactory::create_text(std::string msg, sf::Font* font, sf::Vector2f pos, int size, ALIGN alignment, sf::Color color) { TextGraphic* t = new TextGraphic(msg, font, size); t->set_color(color); t->set_origin(this->get_origin_from_alignment(t->get_local_bounds(), alignment)); t->set_position(pos); return t; }
void TextView::Update () { TextGraphic* gview = (TextGraphic*) GetGraphic(); TextGraphic* gsubj = (TextGraphic*) GetTextComp()->GetGraphic(); IncurDamage(gview); * (Graphic*) gview = * (Graphic*) gsubj; gview->SetLineHeight(gsubj->GetLineHeight()); IncurDamage(gview); EraseHandles(); }
void Grapher::InitVAxis () { for (int v = 1; v <= _vrange; v++) { char num[10]; sprintf(num, "%d", (int)_lorigy+v); TextGraphic* text = new TextGraphic(num, _vlabel); _vlabel_picture->Append(text); text->Translate(0.0, _vinc*(v-1)); _vaxis_picture->Align(Left, text, Right); Graphic* vaxis = _vaxis->Copy(); _vaxis_picture->Append(vaxis); vaxis->Translate(0.0, _vinc*v); } }
void Grapher::InitHAxis () { for (int h = 1; h <= _hrange; h++) { char num[10]; sprintf(num, "%d", (int)_lorigx+h); TextGraphic* text = new TextGraphic(num, _hlabel); _hlabel_picture->Append(text); text->Translate(_hinc*(h-1), 0.0); Graphic* haxis = _haxis->Copy(); _haxis_picture->Append(haxis); haxis->Translate(_hinc*h, 0.0); } }
boolean TextGraphic::operator == (TextGraphic& tg) { const char* tgstring = tg.GetOriginal(); int tgcount = strlen(tgstring); int count = strlen(_string); return (tgcount == count) ? strcmp(tgstring, _string) == 0 : false; }
void TextComp::Interpret (Command* cmd) { TextGraphic* gr = (TextGraphic*) GetGraphic(); if (cmd->IsA(BRUSH_CMD) || cmd->IsA(PATTERN_CMD)) { // do nothing } else if (cmd->IsA(FONT_CMD)) { PSFont* font = ((FontCmd*) cmd)->GetFont(); cmd->Store(this, new VoidData(gr->GetFont())); gr->SetFont(font); gr->SetLineHeight(font->Height()); // hack; should be state var Notify(); } else { GraphicComp::Interpret(cmd); } }
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); }
int TextScript::ReadText (istream& in, void* addr1, void* addr2, void* addr3, void* addr4) { int line_height; char delim; char buf[BUFSIZ]; in >> line_height >> delim; if (in.good()) ParamList::parse_text(in, buf, BUFSIZ); if (!in.good()) { return -1; } else { TextGraphic* tg = new TextGraphic(buf, line_height); tg->FillBg(false); *(TextGraphic**)addr1 = tg; return 0; } }
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; }
void TextComp::Write (ostream& out) { GraphicComp::Write(out); TextGraphic* text = GetText(); out << text->GetLineHeight() << "\n"; WriteString(text->GetOriginal(), out); WriteBgFilled(text->BgFilled(), out); WriteColor(text->GetFgColor(), out); WriteColor(text->GetBgColor(), out); WriteFont(text->GetFont(), out); WriteTransformer(text->GetTransformer(), out); }
void TextComp::Read (istream& in) { GraphicComp::Read(in); int lineHt; in >> lineHt; char* string = ReadString(in); TextGraphic* text = new TextGraphic(string, lineHt); delete string; text->FillBg(ReadBgFilled(in)); PSColor* fg = ReadColor(in); PSColor* bg = ReadColor(in); text->SetColors(fg, bg); text->SetFont(ReadFont(in)); Transformer* t = ReadTransformer(in); text->SetTransformer(t); Unref(t); SetGraphic(text); }
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; }
boolean TextOvComp::operator == (OverlayComp& comp) { if (GetClassId() != comp.GetClassId()) return false; TextGraphic* texta = GetText(); TextGraphic* textb = ((TextOvComp&)comp).GetText(); int lha = texta->GetLineHeight(); int lhb = textb->GetLineHeight(); return lha == lhb && strcmp(texta->GetOriginal(), textb->GetOriginal()) == 0 && OverlayComp::operator==(comp); }
boolean TextScript::Definition (ostream& out) { TextOvComp* comp = (TextOvComp*) GetSubject(); TextGraphic* g = comp->GetText(); const char* text = g->GetOriginal(); int h = g->GetLineHeight(); out << "text("; out << h << ","; int indent_level = 0; Component* parent = comp; do { parent = parent->GetParent(); indent_level++; } while (parent != nil); ParamList::output_text(out, text, indent_level); 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); } Annotation(out); Attributes(out); out << ")"; return out.good(); }
boolean PSText::Definition (ostream& out) { TextComp* comp = (TextComp*) GetSubject(); TextGraphic* g = comp->GetText(); 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(); }
boolean TextFileScript::Definition (ostream& out) { TextFileComp* comp = (TextFileComp*) GetSubject(); TextGraphic* g = comp->GetText(); int h = g->GetLineHeight(); out << "textfile("; out << h << ",\"" << comp->GetPathname() << "\""; if (comp->GetBegstr()) { out << " :begstr "; ParamList::output_text(out, comp->GetBegstr(), 0); } if (comp->GetEndstr()) { out << " :endstr "; ParamList::output_text(out, comp->GetEndstr(), 0); } if (comp->GetLineWidth() > -1) out << " :linewidth " << comp->GetLineWidth(); 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); } Annotation(out); Attributes(out); out << ")"; return out.good(); }