Exemple #1
0
void RDimDiametricData::updateTextData() const {
    initTextData();

    double dimgap = getDimgap();

    if (RMath::isNaN(defaultAngle)) {
        // updates default angle:
        getShapes();
    }

    // move text to the side if appropriate:
    if (!hasCustomTextPosition()) {
        //RBox bbox = textData.getBoundingBox();
        if (!RMath::isNaN(dimLineLength) && textData.getWidth()>dimLineLength) {
            RVector distH;
            distH.setPolar(textData.getWidth()/2.0
                           +dimLineLength/2.0+dimgap, defaultAngle);
            textPositionSide = textPositionCenter;
            textPositionSide+=distH;
        }
        else {
            textPositionSide = RVector::invalid;
        }
    }

    textData.rotate(defaultAngle, RVector(0,0));
    textData.move(getTextPosition());
}
QList<RRefPoint> RDimDiametricData::getReferencePoints(RS::ProjectionRenderingHint hint) const {
    QList<RRefPoint> ret = RDimensionData::getReferencePoints(hint);

    ret.append(getTextPosition());
    ret.append(chordPoint);

    return ret;
}
void WayRenderer::label(cairo_t* cr,
		std::list<shared_ptr<Label> >& labels, AssetCache& cache)
{
	if (s->text.str().size() == 0 || s->font_size <= 0.0)
		return;

	// make sure path is initialized
	addWayPath(cr);
	cairo_new_path(cr);

	cairo_save(cr);

	cairo_set_font_size(cr, s->font_size);

	cairo_select_font_face(cr,
				s->font_family.c_str(),
				s->font_style == Style::STYLE_ITALIC ? CAIRO_FONT_SLANT_ITALIC : CAIRO_FONT_SLANT_NORMAL,
				s->font_weight == Style::WEIGHT_BOLD ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL
			);

	cairo_text_extents_t textSize;
	cairo_text_extents(cr, s->text.c_str(), &textSize);

	if (s->text_position == Style::POSITION_CENTER)
	{
		// request a centered label
		addLabel(labels, bounds.getCenter() + FloatPoint(0.0, s->text_offset), &textSize);
	}
	else if (s->text_position == Style::POSITION_LINE)
	{
		FloatPoint best;
		double angle = 0;
		bool placed = getTextPosition(path, textSize.width, best, angle);

		if (placed) {
			cairo_translate(cr, best.x, best.y);
			cairo_rotate(cr, angle);
			cairo_translate(cr, 0, s->text_offset);

			cairo_move_to(cr, -textSize.width/2.0 - textSize.x_bearing,
						-textSize.height/2.0 - textSize.y_bearing);

			cairo_text_path(cr, s->text.c_str());

			if (s->text_halo_radius > 0.0)
			{
				cairo_set_line_join(cr, CAIRO_LINE_JOIN_ROUND);
				cairo_set_line_width(cr, s->text_halo_radius*2.0);
				cairo_set_source_rgba(cr, COLOR2RGBA(s->text_halo_color));
				cairo_stroke_preserve(cr);
			}
			cairo_set_source_rgba(cr, COLOR2RGBA(s->text_color));
			cairo_fill(cr);
		}
	}

	cairo_restore(cr);
}
Exemple #4
0
void RDimensionData::updateTextData() const {
    initTextData();
    if (RMath::isNaN(defaultAngle)) {
        // updates default angle:
        getShapes();
    }
    textData.rotate(defaultAngle, RVector(0,0));
    textData.move(getTextPosition());
}
Exemple #5
0
QList<RRefPoint> RDimensionData::getReferencePoints(RS::ProjectionRenderingHint hint) const {
    Q_UNUSED(hint)

    QList<RRefPoint> ret;

    ret.append(definitionPoint);
    ret.append(getTextPosition());

    return ret;
}
Exemple #6
0
QList<RRefPoint> RDimAngularData::getReferencePoints(RS::ProjectionRenderingHint hint) const {
    QList<RRefPoint> ret = RDimensionData::getReferencePoints(hint);

    ret.append(getTextPosition());
    ret.append(extensionLine1Start);
    ret.append(extensionLine1End);
    ret.append(extensionLine2Start);
    ret.append(dimArcPosition);

    return ret;
}
Exemple #7
0
void RDimLinearData::updateTextData() const {
    initTextData();

    double dimgap = getDimgap();

    if (RMath::isNaN(defaultAngle)) {
        // updates default angle:
        getShapes();
    }

    // move text to the side if appropriate:
    if (!hasCustomTextPosition()) {
//        RVector newTextPos = dimensionLine.getMiddlePoint();
//        RVector distV;

//        // rotate text so it's readable from the bottom or right (ISO)
//        // quadrant 1 & 4
//        if (corrected) {
//            distV.setPolar(dimgap + dimtxt/2.0, dimAngle1-M_PI/2.0);
//        } else {
//            distV.setPolar(dimgap + dimtxt/2.0, dimAngle1+M_PI/2.0);
//        }

//        // move text away from dimension line:
//        newTextPos+=distV;

//        // TODO: resets textPosition if text was moved to the side for lack of space:
//        textPosition = newTextPos;
//        qDebug() << "RDimensionData::getDimensionLineShapes(): 1: textPosition: " << textPosition;
//        //updateTextData();
//        qDebug() << "RDimensionData::getDimensionLineShapes(): 2: textPosition: " << textPosition;


        if (!RMath::isNaN(dimLineLength) && textData.getWidth()>dimLineLength) {
            RVector distH;
            distH.setPolar(textData.getWidth()/2.0+dimLineLength/2.0+dimgap, defaultAngle);
            textPositionSide = textPositionCenter;
            textPositionSide+=distH;
            //qDebug() << "RDimLinearData::updateTextData(): textPosition (side): " << textPositionCenter;
        }
        else {
            textPositionSide = RVector::invalid;
        }
    }

    textData.rotate(defaultAngle, RVector(0,0));
    textData.move(getTextPosition());
}
Exemple #8
0
QList<RRefPoint> RDimAlignedData::getReferencePoints(RS::ProjectionRenderingHint hint) const {

    Q_UNUSED(hint)

    // we don't want to add definitionPoint, so we don't call the base
    // class implementation here on purpose
    QList<RRefPoint> ret;

    ret.append(getTextPosition());
    ret.append(extensionPoint1);
    ret.append(extensionPoint2);
    ret.append(refDefinitionPoint1);
    ret.append(refDefinitionPoint2);

    return ret;
}
Exemple #9
0
sf::FloatRect TextWidget::getTextRect() const
{
	sf::Vector2f pos = getTextPosition(), size = getTextSize();
	return sf::FloatRect(pos.x, pos.y, size.x, size.y);
}