Esempio n. 1
0
void ActivityDiagram::setGlyphHeight(int id, int height)
{
	Glyph *glyph = getGlyphById(id);
	if (glyph != NULL)
		glyph->setHeight(height);
	notify();
}
int traceConicBezier(FT_VECTOR_PARAMETER *control, FT_VECTOR_PARAMETER *to, void *obj)
{
	Glyph *glyph = reinterpret_cast<Glyph *>(obj);
	Affine &affine = glyph->affine();
	BezierPathLibart *path = static_cast<BezierPathLibart *>(glyph->modifiableBezierPath());

	int index = path->m_array.count();
	if(!(index > 0))
		return -1;

	path->m_array.resize(index + 1);
	ArtBpath *s = &path->m_array[index - 1];
	ArtBpath *e = &path->m_array[index];

	e->code = ART_CURVETO;

	Point c = affine.mapPoint(Point(control->x, control->y));
	Point p = affine.mapPoint(Point(to->x, to->y));
	e->x3 = p.x();
	e->y3 = p.y();

	path->m_array[index].x1 = c.x() - (c.x() - s->x3) / 3;
	path->m_array[index].y1 = c.y() - (c.y() - s->y3) / 3;
	path->m_array[index].x2 = c.x() + (e->x3 - c.x()) / 3;
	path->m_array[index].y2 = c.y() + (e->y3 - c.y()) / 3;

	return 0;
}
Esempio n. 3
0
void Text::sizeChanged()
{
	textX = 0;
	ellipsisStop = String::Iterator();
	if (isHeightAuto())
		height = font->getLineHeight();
	if (isWidthAuto())
		width = font->getTextWidth(string);
	else {
		if ((flags & (ALIGN_RIGHT | ALIGN_CENTER | ELLIPSIS)) != 0) {
			int w = 0;
			String::Iterator i = string.start();
			int c = -1;
			while (w <= getWidth() && (c = i.getForward()) != -1)
				w += font->getGlyph(Font::getGlyphIndex(c)).getWidth();
			if ((flags & ELLIPSIS) != 0 && w > getWidth()) {
				Glyph ellipsis = font->getCharGlyph(CHAR_ELLIPSIS);
				ellipsisStop = i;
				while (w > width - ellipsis.getWidth() && (c = ellipsisStop.getBackward()) != -1)
					w -= font->getGlyph(Font::getGlyphIndex(c)).getWidth();
				if (c == -1)
					ellipsisStop = string.start();
				w += ellipsis.getWidth();
			}
			if (w < getWidth()) {
				if ((flags & ALIGN_RIGHT) != 0)
					textX = getWidth() - w;
				else if ((flags & ALIGN_CENTER) != 0)
					textX = (getWidth() - w) / 2;
			}
		}
	}
}
Esempio n. 4
0
void TBScrollBox::request(Requisition& req) const {
    GlyphIndex n = count();
    TBScrollBoxImpl& sb = *impl_;
    if (sb.changed_) {
	Requisition r;
	const Requirement& rx = r.x_requirement();
	const Requirement& ry = r.y_requirement();
	Coord natural_width = 0.0;
	Coord natural_height = 0.0;
	for (GlyphIndex i = 0; i < n; i++) {
	    Glyph* g = component(i);
	    if (g != nil) {
		g->request(r);
		Coord r_width = rx.natural();
		if (r_width > natural_width) {
		    natural_width = r_width;
		}
		natural_height += ry.natural();
	    }
	}
	Requirement& box_x = sb.requisition_.x_requirement();
	box_x.natural(natural_width);
	box_x.stretch(fil);
	box_x.shrink(natural_width);
	box_x.alignment(0.0);

	Requirement& box_y = sb.requisition_.y_requirement();
	box_y.natural(natural_height);
	box_y.stretch(fil);
	box_y.shrink(natural_height);
	box_y.alignment(1.0);
	sb.changed_ = false;
    }
    req = sb.requisition_;
}
Esempio n. 5
0
//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button)
{
    prevMousePos = mousePos;
    mousePos.set(x, y);

    VF.addInwardCircle(x, y, 600, 0.1f);
    VF.addClockwiseCircle(x, y, 260, 0.3f);

    if (mode == 1) {  // DRAG MODE
        if (words.size() > 0) {
//            words.back().moveTo(mousePos);
        }
    }
    else if (mode == 2) {  // SPRAY MODE
        if (prevMousePos.distance(mousePos) > 10) {
            float targetScale = ofMap(mousePos.distance(prevMousePos), 0, MAX(ofGetWidth(), ofGetHeight()), 10, 500);
            float targetRotation = RAD_TO_DEG * (atan2(prevMousePos.y - mousePos.y, prevMousePos.x - mousePos.x));

            // Add a new Glyph to the last Word.
            Glyph *glyph = new Glyph();
            glyph->setInitialCondition(mousePos, ofVec2f());
            glyph->setScale(targetScale);
            glyph->setRotation(targetRotation);
            glyph->addForce((mousePos - prevMousePos) * 0.5);
            words.back()->addGlyph(glyph);
        }
    }
}
Esempio n. 6
0
File: box.cpp Progetto: PNCG/neuron
void BoxImpl::full_allocate(AllocationInfo& info) {
    Canvas* c = info.canvas();
    GlyphIndex n = box_->count();
    Allocation* a = info.component_allocations();
    Requisition* r = new Requisition[n];
    GlyphIndex i;
    for (i = 0; i < n; i++) {
        Glyph* g = box_->component(i);
        if (g != nil) {
            g->request(r[i]);
        }
    }
    layout_->allocate(info.allocation(), n, r, a);
    delete [] r;

    Extension& box = info.extension();
    Extension child;
    for (i = 0; i < n; i++) {
        Glyph* g = box_->component(i);
        if (g != nil) {
            child.clear();
            g->allocate(c, a[i], child);
            box.merge(child);
        }
    }
}
Esempio n. 7
0
int BitmapFont::computeVisibleGlyphs ( const std::string& str, int start, int end, float availableWidth ) {
    int index = start;
    float width = 0;
    Glyph* lastGlyph = NULL;
    if ( data->scaleX == 1 ) {
        for ( ; index < end; index++ ) {
            char ch = str[index];
            Glyph* g = data->getGlyph ( ch );
            if ( g != NULL ) {
                if ( lastGlyph != NULL ) width += lastGlyph->getKerning ( ch );
                lastGlyph = g;
                if ( width + g->xadvance > availableWidth ) break;
                width += g->xadvance;
            }
        }
    } else {
        float scaleX = this->data->scaleX;
        for ( ; index < end; index++ ) {
            char ch = str[index];
            Glyph* g = data->getGlyph ( ch );
            if ( g != NULL ) {
                if ( lastGlyph != NULL ) width += lastGlyph->getKerning ( ch ) * scaleX;
                lastGlyph = g;
                if ( width + g->xadvance * scaleX > availableWidth ) break;
                width += g->xadvance * scaleX;
            }
        }
    }
    return index - start;
}
void SuperGlyph::create(float _scale){
    limbs.clear();
    
    //  Make a new Glyph
    //
    Glyph *glyph = new Glyph();
    glyph->setScale(_scale);
    
    //  Transform it to Shapes
    //
    for (int i = 0; i < glyph->limbs().size(); i++){
        Shape newShape;
        newShape.makeFromLimb(i, *glyph);
        newShape.bDebug = &bDebug;
        limbs.push_back( newShape );
    }
    
    //  Make a path from the shapes
    //
    insidePath.clear();
    for (int i = 0; i < limbs.size(); i++){
        for (int j = 0; j < limbs[i].getVertices().size(); j++) {
            ofPoint vert = limbs[i].getVertices()[j];
            insidePath.addVertex( vert );
        }
    }
    insidePath.close();
    perimeter = insidePath.getPerimeter();
    
    this->set( insidePath.getBoundingBox() );
}
Esempio n. 9
0
void ActivityDiagram::paste()
{
	//map<sample, clone>
	map<Glyph*, Glyph*> glyphMap;
	// 新增
	for (unsigned int i = 0; i < _copyGlyphs.size(); i++)
	{
		int id = _idCount;
		_idCount++;
		Glyph *glyphClone = addGlyph(id, _copyGlyphs[i]->getType(), _copyGlyphs[i]->getText());
		glyphClone->setWidth(_copyGlyphs[i]->getWidth());
		glyphClone->setHeight(_copyGlyphs[i]->getHeight());
		if (glyphClone->getType() == EDGE)
		{
			glyphClone->setWidth(glyphClone->getWidth() + DELTA_X);
			glyphClone->setHeight(glyphClone->getHeight() + DELTA_Y);
		}
		glyphClone->setX(_copyGlyphs[i]->getX() + DELTA_X);
		glyphClone->setY(_copyGlyphs[i]->getY() + DELTA_Y);
		glyphMap.insert(pair<Glyph*, Glyph*>(_copyGlyphs[i], glyphClone));
	}
	connectCopyGlyph(_copyGlyphs, glyphMap);

	notify();
}
Esempio n. 10
0
int BitmapFont::computeVisibleGlyphs ( const std::string& str, unsigned int start, unsigned int end, float availableWidth ) {
    unsigned int index = start;
    float width = 0;
    Glyph* lastGlyph = NULL;
    if ( data->scaleX == 1 ) {
        for ( ; index < end; ) {
            Glyph* g = nullptr;            
            unsigned int ch = data->getGlyph ( str , index, g  );
            if ( g != NULL ) {
                if ( lastGlyph != NULL ) width += lastGlyph->getKerning ( ch );
                lastGlyph = g;
                if ( width + g->xadvance > availableWidth ) break;
                width += g->xadvance;
            }
        }
    } else {
        float scaleX = this->data->scaleX;
        for ( ; index < end; ) {
            Glyph* g = nullptr;            
            unsigned int ch = data->getGlyph ( str , index, g  );
            if ( g != NULL ) {
                if ( lastGlyph != NULL ) width += lastGlyph->getKerning ( ch ) * scaleX;
                lastGlyph = g;
                if ((width + g->xadvance * scaleX) - availableWidth > 0.000001f ) break;
                width += g->xadvance * scaleX;
            }
        }
    }
    return index - start;
}
Esempio n. 11
0
void ActivityDiagram::setHasConnectionPoint(int id, bool hasConnectionPoint)
{
	Glyph *glyph = getGlyphById(id);
	if (glyph != NULL)
		glyph->setHasConnectionPoint(hasConnectionPoint);
	notify();
}
Esempio n. 12
0
void ActivityDiagram::setGlyphWidth(int id, int width)
{
	Glyph *glyph = getGlyphById(id);
	if (glyph != NULL)
		glyph->setWidth(width);
	notify();
}
Esempio n. 13
0
bool ActivityDiagram::deleteGlyph(int id)
{
	Glyph *glyph = getGlyphById(id);

	// 切斷連結
	vector<Glyph*> targetGlyphs =  glyph->getTargets();
	for (unsigned int i = 0; i < targetGlyphs.size(); i++)
		deleteConnection(id, targetGlyphs[i]->getId());
	vector<Glyph*> sourceGlyphs =  glyph->getSources();
	for (unsigned int i = 0; i < sourceGlyphs.size(); i++)
		deleteConnection(sourceGlyphs[i]->getId(), id);

	// 從 _glyphs 中移除
	for (unsigned int i = 0; i < _glyphs.size(); i++)
	{
		if (_glyphs[i] == glyph)
		{
			delete _glyphs[i];
			_glyphs.erase(_glyphs.begin() + i);
			notify();
			return true;
		}
	}
	notify();
	return false;	
}
Esempio n. 14
0
void ActivityDiagram::setIsSelected(int id, bool isSelected)
{
	Glyph *glyph = getGlyphById(id);
	if (glyph != NULL)
		glyph->isSelected(isSelected);
	notify();
}
Esempio n. 15
0
/** Traces all glyphs of the current font and stores them in the cache. If caching is disabled, nothing happens.
 *  @param[in] includeCached if true, glyphs already cached are traced again
 *  @param[in] cb optional callback methods called by the tracer
 *  @return number of glyphs traced */
int PhysicalFont::traceAllGlyphs (bool includeCached, GFGlyphTracer::Callback *cb) const {
	int count = 0;
	if (type() == MF && CACHE_PATH) {
		if (const FontMetrics *metrics = getMetrics()) {
			int fchar = metrics->firstChar();
			int lchar = metrics->lastChar();
			string gfname;
			Glyph glyph;
			if (createGF(gfname)) {
				_cache.read(name().c_str(), CACHE_PATH);
				double ds = getMetrics() ? getMetrics()->getDesignSize() : 1;
				GFGlyphTracer tracer(gfname, unitsPerEm()/ds, cb);
				tracer.setGlyph(glyph);
				for (int i=fchar; i <= lchar; i++) {
					if (includeCached || !_cache.getGlyph(i)) {
						glyph.clear();
						tracer.executeChar(i);
						glyph.closeOpenSubPaths();
						_cache.setGlyph(i, glyph);
						++count;
					}
				}
				_cache.write(CACHE_PATH);
			}
		}
	}
	return count;
}
Esempio n. 16
0
void ActivityDiagram::setGlyphY(int id, int y)
{
	Glyph *glyph = getGlyphById(id);
	if (glyph != NULL)
		glyph->setY(y);
	notify();
}
Esempio n. 17
0
void ActivityDiagram::setGlyphX(int id, int x)
{
	Glyph *glyph = getGlyphById(id);
	if (glyph != NULL)
		glyph->setX(x);
	notify();
}
Esempio n. 18
0
void ActivityDiagram::setGlyphText(int id, string text)
{
	Glyph *glyph = getGlyphById(id);
	if (glyph != NULL)
		glyph->setText(text);
	notify();
}
Esempio n. 19
0
GlyphProperty ActivityDiagram::getGlyphProperty(int id)
{
	GlyphProperty glyphProperty;
	Glyph *glyph = getGlyphById(id);
	if (glyph != NULL)
		glyphProperty = glyph->getProperties();
	return glyphProperty;
}
Esempio n. 20
0
void Deck::print(Printer* p, const Allocation& a) const {
    if (card_ >= 0 && card_ < count()) {
	Glyph* g = component(card_);
	if (g != nil) {
	    g->print(p, a);
	}
    }
}
Esempio n. 21
0
void Deck::undraw() {
    if (card_ >= 0 && card_ < count()) {
	Glyph* g = component(card_);
	if (g != nil) {
	    g->undraw();
	}
    }
}
Esempio n. 22
0
void Deck::draw(Canvas* c, const Allocation& a) const {
    if (card_ >= 0 && card_ < count()) {
	Glyph* g = component(card_);
	if (g != nil) {
	    g->draw(c, a);
	}
    }
}
Esempio n. 23
0
void LayoutLayer::print(Printer* p, const Allocation& a) const {
    if (under_ != nil) {
	under_->print(p, a);
    }
    MonoGlyph::print(p, a);
    if (over_ != nil) {
	over_->print(p, a);
    }
}
Esempio n. 24
0
void LayoutLayer::undraw() {
    if (under_ != nil) {
	under_->undraw();
    }
    MonoGlyph::undraw();
    if (over_ != nil) {
	over_->undraw();
    }
}
Esempio n. 25
0
vector<int> ActivityDiagram::getGlyphSourceIds(int id)
{
	Glyph *glyph = getGlyphById(id);
	vector<int> ids;
	if (glyph != NULL)
		ids = glyph->getSourceIds();
	
	return ids;
}
Esempio n. 26
0
string ActivityDiagram::getGlyphText(int id)
{
	string text = "";
	Glyph *glyph = getGlyphById(id);
	if (glyph != NULL)
		text = glyph->getText();

	return text;
}
Esempio n. 27
0
vector<DrawInstruction> ActivityDiagram::getDrawInstructions(int id)
{
	vector<DrawInstruction> drawInstructions;
	Glyph *glyph = getGlyphById(id);
	if (glyph != NULL)
		drawInstructions = glyph->getDrawInstructions();

	return drawInstructions;
}
Esempio n. 28
0
GLYPH_TYPE ActivityDiagram::getGlyphType(int id)
{
	GLYPH_TYPE type = ERROR_GLYPH;
	Glyph *glyph = getGlyphById(id);
	if (glyph != NULL)
		type = glyph->getType();
	
	return type;
}
Esempio n. 29
0
void LayoutLayer::draw(Canvas* c, const Allocation& a) const {
    if (under_ != nil) {
	under_->draw(c, a);
    }
    MonoGlyph::draw(c, a);
    if (over_ != nil) {
	over_->draw(c, a);
    }
}
Esempio n. 30
0
void LayoutLayer::pick(Canvas* c, const Allocation& a, int depth, Hit& h) {
    if (under_ != nil) {
	under_->pick(c, a, depth, h);
    }
    MonoGlyph::pick(c, a, depth, h);
    if (over_ != nil) {
	over_->pick(c, a, depth, h);
    }
}