void CreateOpenSplineFunc::execute() { ComValue& vect = stack_arg(0); if (!vect.is_type(ComValue::ArrayType) || vect.array_len()==0) { reset_stack(); push_stack(ComValue::nullval()); return; } const int len = vect.array_len(); const int npts = len/2; int x[npts]; int y[npts]; ALIterator i; AttributeValueList* avl = vect.array_val(); avl->First(i); for (int j=0; j<npts && !avl->Done(i); j++) { x[j] = avl->GetAttrVal(i)->int_val(); avl->Next(i); y[j] = avl->GetAttrVal(i)->int_val(); avl->Next(i); } AttributeList* al = stack_keys(); Resource::ref(al); reset_stack(); PasteCmd* cmd = nil; if (npts) { BrushVar* brVar = (BrushVar*) _ed->GetState("BrushVar"); PatternVar* patVar = (PatternVar*) _ed->GetState("PatternVar"); ColorVar* colVar = (ColorVar*) _ed->GetState("ColorVar"); Transformer* rel = get_transformer(al); ArrowVar* aVar = (ArrowVar*) _ed->GetState("ArrowVar"); ArrowOpenBSpline* openspline = new ArrowOpenBSpline(x, y, npts, aVar->Head(), aVar->Tail(), _ed->GetViewer()->GetMagnification(), stdgraphic); if (brVar != nil) openspline->SetBrush(brVar->GetBrush()); if (patVar != nil) openspline->SetPattern(patVar->GetPattern()); if (colVar != nil) { openspline->FillBg(!colVar->GetBgColor()->None()); openspline->SetColors(colVar->GetFgColor(), colVar->GetBgColor()); } openspline->SetTransformer(rel); Unref(rel); ArrowSplineOvComp* comp = new ArrowSplineOvComp(openspline); comp->SetAttributeList(al); if (PasteModeFunc::paste_mode()==0) cmd = new PasteCmd(_ed, new Clipboard(comp)); ComValue compval(new OverlayViewRef(comp), symbol_add("ArrowSplineComp")); push_stack(compval); execute_log(cmd); } else push_stack(ComValue::nullval()); Unref(al); }
long * ygeta_l(int iarg, long *ntot, long *dims) { Operations *ops; Member *type; void *p; if (iarg < 0) return 0; p = ygeta_array(iarg, &ops, &type); yget_dims(ntot, dims, type); if (ops != &longOps) { if (type->dims) { long *q = ypush_array(&longStruct, type->dims); y_to_l[ops->promoteID](p, q, type->number); sp[-iarg-1].ops = &intScalar; Unref(sp[-iarg-1].value.db); sp--; sp[-iarg].value.db = sp[1].value.db; sp[-iarg].ops = &dataBlockSym; return q; } else { int is_db = (sp[-iarg].ops == &dataBlockSym); long x; y_to_l[ops->promoteID](p, &x, type->number); sp[-iarg].ops = &longScalar; if (is_db) Unref(sp[-iarg].value.db); sp[-iarg].value.l = x; return &(sp[-iarg].value.l); } } return p; }
double * ygeta_dz(int iarg, long *ntot, long *dims, int *is_z) { Operations *ops; Member *type; void *p; if (iarg < 0) return 0; p = ygeta_array(iarg, &ops, &type); yget_dims(ntot, dims, type); *is_z = (ops==&complexOps); if (ops!=&doubleOps && !*is_z) { if (type->dims) { double *q = ypush_array(&doubleStruct, type->dims); y_to_d[ops->promoteID](p, q, type->number); sp[-iarg-1].ops = &intScalar; Unref(sp[-iarg-1].value.db); sp--; sp[-iarg].value.db = sp[1].value.db; sp[-iarg].ops = &dataBlockSym; return q; } else { int is_db = (sp[-iarg].ops == &dataBlockSym); double x; y_to_d[ops->promoteID](p, &x, type->number); sp[-iarg].ops = &doubleScalar; if (is_db) Unref(sp[-iarg].value.db); sp[-iarg].value.d = x; return &(sp[-iarg].value.d); } } return p; }
void LinkComp::Read (istream& in) { GraphicComp::Read(in); Line* line = new Line(0, 0, 1, 1); Transformer* t = ReadTransformer(in); line->SetTransformer(t); Unref(t); _conn1 = (Connector*) unidraw->GetCatalog()->ReadComponent(in); _conn2 = (Connector*) unidraw->GetCatalog()->ReadComponent(in); Graphic* parent = new Picture; parent->FillBg(ReadBgFilled(in)); PSColor* fg = ReadColor(in); PSColor* bg = ReadColor(in); parent->SetColors(fg, bg); parent->SetBrush(ReadBrush(in)); t = ReadTransformer(in); parent->SetTransformer(t); Unref(t); parent->Append(line, _conn1->GetGraphic(), _conn2->GetGraphic()); SetGraphic(parent); }
void CreateLineFunc::execute() { const int x0 = 0; const int y0 = 1; const int x1 = 2; const int y1 = 3; const int n = 4; int coords[n]; ComValue& vect = stack_arg(0); 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++) { coords[j] = avl->GetAttrVal(i)->int_val(); avl->Next(i); } AttributeList* al = stack_keys(); Resource::ref(al); reset_stack(); PasteCmd* cmd = nil; if (coords[x0] != coords[x1] || coords[y0] != coords[y1]) { BrushVar* brVar = (BrushVar*) _ed->GetState("BrushVar"); PatternVar* patVar = (PatternVar*) _ed->GetState("PatternVar"); ColorVar* colVar = (ColorVar*) _ed->GetState("ColorVar"); Transformer* rel = get_transformer(al); ArrowVar* aVar = (ArrowVar*) _ed->GetState("ArrowVar"); ArrowLine* line = new ArrowLine(coords[x0], coords[y0], coords[x1], coords[y1], aVar->Head(), aVar->Tail(), _ed->GetViewer()->GetMagnification(), stdgraphic); if (brVar != nil) line->SetBrush(brVar->GetBrush()); if (colVar != nil) { line->FillBg(!colVar->GetBgColor()->None()); line->SetColors(colVar->GetFgColor(), colVar->GetBgColor()); } line->SetTransformer(rel); Unref(rel); ArrowLineOvComp* comp = new ArrowLineOvComp(line); comp->SetAttributeList(al); if (PasteModeFunc::paste_mode()==0) cmd = new PasteCmd(_ed, new Clipboard(comp)); ComValue compval(new OverlayViewRef(comp), symbol_add("ArrowLineComp")); push_stack(compval); execute_log(cmd); } else push_stack(ComValue::nullval()); Unref(al); }
void ArrowInteractor::SetColors (PSColor* fg, PSColor* bg) { Ref(fg); Ref(bg); Unref(_fg); Unref(_bg); _fg = fg; _bg = bg; }
Graphic::~Graphic () { #ifdef LEAKCHECK _leakchecker->destroy(); #endif Unref(_fg); Unref(_bg); Unref(_t); }
void CreateEllipseFunc::execute() { const int x0 = 0; const int y0 = 1; const int r1 = 2; const int r2 = 3; const int n = 4; int args[n]; ComValue& vect = stack_arg(0); 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); } AttributeList* al = stack_keys(); Resource::ref(al); reset_stack(); PasteCmd* cmd = nil; if (args[r1] > 0 && args[r2] > 0) { BrushVar* brVar = (BrushVar*) _ed->GetState("BrushVar"); PatternVar* patVar = (PatternVar*) _ed->GetState("PatternVar"); ColorVar* colVar = (ColorVar*) _ed->GetState("ColorVar"); Transformer* rel = get_transformer(al); SF_Ellipse* ellipse = new SF_Ellipse(args[x0], args[y0], args[r1], args[r2], stdgraphic); if (brVar != nil) ellipse->SetBrush(brVar->GetBrush()); if (patVar != nil) ellipse->SetPattern(patVar->GetPattern()); if (colVar != nil) { ellipse->FillBg(!colVar->GetBgColor()->None()); ellipse->SetColors(colVar->GetFgColor(), colVar->GetBgColor()); } ellipse->SetTransformer(rel); Unref(rel); EllipseOvComp* comp = new EllipseOvComp(ellipse); comp->SetAttributeList(al); if (PasteModeFunc::paste_mode()==0) cmd = new PasteCmd(_ed, new Clipboard(comp)); ComValue compval( new OverlayViewRef(comp), symbol_add("EllipseComp")); push_stack(compval); execute_log(cmd); } else push_stack(ComValue::nullval()); Unref(al); }
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); }
void Graphic::SetColors (PSColor* fg, PSColor* bg) { Ref(fg); Ref(bg); Unref(_fg); Unref(_bg); _fg = fg; _bg = bg; }
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; }
void StencilComp::Read (istream& in) { GraphicComp::Read(in); Bitmap* image = ReadBitmap(in); Bitmap* mask = nil; Skip(in); int m; in >> m; if (m == valid_mask) { mask = ReadBitmap(in); } else if (m == mask_equals_image) { mask = image; } UStencil* stencil = new UStencil(image, mask); stencil->FillBg(ReadBgFilled(in)); PSColor* fg = ReadColor(in); PSColor* bg = ReadColor(in); stencil->SetColors(fg, bg); Transformer* t = ReadTransformer(in); stencil->SetTransformer(t); Unref(t); SetGraphic(stencil); _filename = ReadString(in); }
void JSFiber::js_callback() { scope s(this); v8::Local<v8::Value> retVal; callFunction(retVal); Unref(); }
void DragManip::SetTransformer (Transformer* t) { if (_relative != t) { Ref(t); Unref(_relative); _relative = t; } }
void NodeMap::renderFinished() { Nan::HandleScope scope; // We're done with this render call, so we're unrefing so that the loop could close. uv_unref(reinterpret_cast<uv_handle_t *>(async)); // There is no render pending anymore, we the GC could now delete this object if it went out // of scope. Unref(); // Move the callback and image out of the way so that the callback can start a new render call. auto cb = std::move(callback); auto img = std::move(image); assert(cb); // These have to be empty to be prepared for the next render call. assert(!callback); assert(!image.data); if (error) { std::string errorMessage; try { std::rethrow_exception(error); } catch (const std::exception& ex) { errorMessage = ex.what(); } v8::Local<v8::Value> argv[] = { Nan::Error(errorMessage.c_str()) }; // This must be empty to be prepared for the next render call. error = nullptr; assert(!error); cb->Call(1, argv); } else if (img.data) { v8::Local<v8::Object> pixels = Nan::NewBuffer( reinterpret_cast<char *>(img.data.get()), img.size(), // Retain the data until the buffer is deleted. [](char *, void * hint) { delete [] reinterpret_cast<uint8_t*>(hint); }, img.data.get() ).ToLocalChecked(); img.data.release(); v8::Local<v8::Value> argv[] = { Nan::Null(), pixels }; cb->Call(2, argv); } else { v8::Local<v8::Value> argv[] = { Nan::Error("Didn't get an image") }; cb->Call(1, argv); } }
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 FreeDratMesh(void *dmesh) { DratMesh *dm= dmesh; double *z= dm->mesh.mesh.z; double *r= dm->mesh.mesh.r; DiscardMesh(&dm->mesh); if (z) { Array *array= Pointee(z); Unref(array); } if (r) { Array *array= Pointee(r); Unref(array); } p_free(dmesh); }
void SF_ClosedBSpline::SetBrush (PSBrush* br) { if (_br != br) { Ref(br); Unref(_br); _br = br; invalidateCaches(); } }
void IndexedPtsMixin::reset_indexed_pts() { if (_ptsbuf) { for (int i=0; i<_ptsnum; i++) Unref(_ptsbuf[i]); delete _ptsbuf; _ptsbuf = nil; } }
void ULabel::SetFont (PSFont* font) { if (_font != font) { Ref(font); Unref(_font); _font = font; invalidateCaches(); } }
void Point::SetBrush (PSBrush* br) { if (_br != br) { Ref(br); Unref(_br); _br = br; invalidateCaches(); } }
int Vertices::SetOriginal (const Coord* x, const Coord* y) { MultiLineObj* mlo = MultiLineObj::make_pts(x, y, count()); Unref(_pts); _pts = mlo; Resource::ref(_pts); uncacheExtent(); return count(); }
void Rubberband::SetPainter (Painter* p) { if (p != output) { p->Reference(); Unref(output); output = p; output->Begin_xor(); } }
void SF_MultiLine::SetBrush (PSBrush* br) { if (_br != br) { Ref(br); Unref(_br); _br = br; invalidateCaches(); } }
void FullGraphic::SetFont (PSFont* font) { if (_font != font) { Ref(font); Unref(_font); _font = font; invalidateCaches(); } }
void FullGraphic::SetBrush (PSBrush* br) { if (_br != br) { Ref(br); Unref(_br); _br = br; invalidateCaches(); } }
void DragManip::SetRubberband (Rubberband* newr) { if (_r != newr) { Ref(newr); Unref(_r); _r = newr; if (_r != nil) _viewer->InitRubberband(_r); } }
void Painter::SetTransformer(Transformer *t) { if (matrix != t) { Unref(matrix); matrix = t; if (matrix != nil) { matrix->Reference(); } } }
/* same as PopToD in ops0.c */ static void pop_to_d(Symbol *s) { Array *array = (Array *)sp->value.db; PopTo(s); if (s->ops==&dataBlockSym && !array->type.dims) { s->ops= &doubleScalar; s->value.d= array->value.d[0]; Unref(array); } }