virtual void subViewportDraw(AcGiViewportDraw* vportDrawContext)
	{
		// Calculate the size of the glyph in WCS (use for text height factor)
		int glyphPixels = acdbCustomOsnapManager()->osnapGlyphSize();
		AcGePoint2d glyphSize;
		vportDrawContext->viewport().getNumPixelsInUnitSquare( m_center, glyphSize );
		double glyphHeight = glyphPixels / glyphSize[ Y ];

		// Get the extents of the glyph text, so we can centre it
		AcGiTextStyle style;
		AcGePoint2d ptExt = style.extents( ASDK_GLYPH_TEXT, Adesk::kFalse, -1, Adesk::kFalse );

		struct resbuf rbFrom, rbTo;
		rbFrom.restype = RTSHORT;
		rbFrom.resval.rint = 2; // From DCS
		rbTo.restype = RTSHORT;
		rbTo.resval.rint = 0; // To WCS

		// Translate the X-axis of the DCS to WCS co-ordinates (as a displacement vector)
		AcGeVector3d ptDir;
		acedTrans( asDblArray( AcGeVector3d::kXAxis ),
			&rbFrom, 
			&rbTo, 
			1, 
			asDblArray( ptDir ));

		// Translate the centre of the glyph from DCS to WCS co-ordinates
		AcGePoint3d ptPos, ptCen;
		AcGeVector3d vecExt( ptExt[ X ] / 2, ptExt[ Y ] / 2, 0 );
		ptPos = m_center - vecExt / 2; 
		if ( RTNORM != acedTrans( asDblArray( ptPos ),
			&rbFrom,
			&rbTo,
			0,
			asDblArray( ptCen )))
			ptCen = m_center;

		// Draw the centred text representing the glyph
		vportDrawContext->geometry().text( ptCen,
			vportDrawContext->viewport().viewDir(),
			ptDir, 
			glyphHeight, 
			1.0,
			0.0,
			ASDK_GLYPH_TEXT );

	}
// Get an AcGiTextStyle from an AcDbTextStyleTableRecord.
// Try to map as many characteristics as we can.
//
Acad::ErrorStatus
rx_getTextStyle(AcGiTextStyle &newStyle, AcDbObjectId styleId)
{
    AcDbTextStyleTableRecord *oldStyle;
    Acad::ErrorStatus es = acdbOpenAcDbObject((AcDbObject *&)oldStyle,
                             styleId, AcDb::kForRead);
    if (es == Acad::eOk) {
        const TCHAR *tmpStr;
        if ((es = oldStyle->fileName(tmpStr)) != Acad::eOk) {
            oldStyle->close();
            return es;
        }
        newStyle.setFileName(tmpStr);

        if ((es = oldStyle->bigFontFileName(tmpStr)) != Acad::eOk) {
            oldStyle->close();
            return es;
        }
        newStyle.setBigFontFileName(tmpStr);

        newStyle.setTextSize(oldStyle->textSize());
        newStyle.setXScale(oldStyle->xScale());
        newStyle.setObliquingAngle(oldStyle->obliquingAngle());

        oldStyle->close();
        newStyle.loadStyleRec();
    }
    return es;
}
Beispiel #3
0
Adesk::Boolean
AsdkTextStyleSamp::worldDraw(AcGiWorldDraw* pW)
{
    AcGePoint3d pos(4.0, 4.0, 0.0);
    AcGeVector3d norm(0.0, 0.0, 1.0);
    AcGeVector3d dir(-1.0, -0.2, 0.0);
    char *pStr = "This is a percent, '%%%'.";
    int len = strlen(pStr);
    AcGiTextStyle style;

    AcGeVector3d vec = norm;
    vec = vec.crossProduct(dir);
    dir = vec.crossProduct(norm);

    style.setFileName("txt.shx");
    style.setBigFontFileName("");
    int status;
    if (!((status = style.loadStyleRec()) & 1))
        pStr = "Font not found.";

    pW->geometry().text(pos, norm, dir, pStr, len,
        Adesk::kFalse, style);

    pos.y += 2.0;

    style.setTrackingPercent(0.8); 
	style.setObliquingAngle(0.5);

    AcGePoint2d ext = style.extents(pStr, Adesk::kFalse,
        strlen(pStr), Adesk::kFalse);

    pW->geometry().text(pos, norm, dir, pStr, len,
        Adesk::kFalse, style);

    // Draw a rectangle around the last text drawn.
    // First you have to create a polyline the size of the
    // bounding box, then you have to transform it to the
    // correct orientation, and then to the location of the
    // text.
    
    // Compute the matrix that orients the box.
    //
    AcGeMatrix3d textMat;
    norm.normalize();
    dir.normalize();
    AcGeVector3d yAxis = norm;
    yAxis = yAxis.crossProduct(dir);
    yAxis.normalize();
    textMat.setCoordSystem(AcGePoint3d(0.0, 0.0, 0.0), dir,
        yAxis, norm);

    // Create the bounding box and enlarge it somewhat.
    //
    double offset = ext.y / 2.0;
    AcGePoint3d verts[5];
    verts[0] = verts[4] = AcGePoint3d(-offset, -offset, 0.0);
    verts[1] = AcGePoint3d(ext.x + offset, -offset, 0.0);
    verts[2] = AcGePoint3d(ext.x + offset, ext.y + offset, 0.0);
    verts[3] = AcGePoint3d(-offset, ext.y + offset, 0.0);

    // Orient and then translate each point in the
    // bounding box.
    //
    for (int i = 0; i < 5; i++) {
        verts[i].transformBy(textMat);
        verts[i].x += pos.x;
        verts[i].y += pos.y;
        verts[i].z += pos.z;
    }
    pW->geometry().polyline(5, verts);

    return Adesk::kTrue;
}