Esempio n. 1
0
/*****************************************************
**
**   Painter   ---   getTextExtent
**
******************************************************/
MPoint Painter::getTextExtent( const MToken &token )
{
	const wxFont oldFont = getCurrentFont();
	wxString s;
	Lang lang;
	SheetFormatter formatter( writercfg );
	MPoint p;

	wxChar symbol = 0;
	SymbolProvider sp( writercfg );
	switch ( token.entity )
	{
		case TTSE_PLANET:
			if ( writercfg->planetSymbols ) symbol = sp.getPlanetCode( (ObjectId)token.entityId );
			if ( ! symbol ) s = formatter.getObjectNamePlain( (ObjectId)token.entityId, token.textFormat, token.vedic );
		break;
		case TTSE_SIGN:
			if ( writercfg->signSymbols ) symbol = sp.getSignCode( (Rasi)token.entityId );
			if ( ! symbol ) s = lang.getSignName( (Rasi)token.entityId, token.textFormat ); //, writercfg->vedicSignNames );
		break;
		case TTSE_ASPECT:
			symbol = SymbolProvider().getAspectCode( (ASPECT_TYPE)token.entityId );
			if ( ! symbol ) s = AspectExpert::getAspectShortDescription( (int)token.entityId );
		break;
		case TTSE_DIRECTION:
			symbol = sp.getRetroCode( (MOVING_DIRECTION)token.entityId );
			if ( ! symbol ) s = wxT( "R" );
		break;
		default:
			symbol = 0;
			s = token.text;
		break;
	}
	if ( symbol )
	{
		const int pointSize = oldFont.GetPointSize();
		setFont( *FontProvider::get()->getFontBySize( FONT_GRAPHIC_SYMBOLS, pointSize ));
		p = getTextExtent( symbol );
	}
	else
	{
		p = getTextExtent( s );
	}

	setFont( oldFont );
	return p;
}
Esempio n. 2
0
void
Port::drawText(const char* text, const Point& loc, int size, uint32 style, Color rgba) {
	if (text == 0) return;
	int len = std::strlen(text);
	if (len == 0) return;
	// look for text entirely outside clip rect
	PortImpl& port = static_cast<PortImpl&>(*this); // get us access to our private data
	Rect drawable = port.drawableRect();
	// cheapest checks, off to right and left
	if (((style & (Graphics::textStyle_Centered | Graphics::textStyle_RightJustified)) == 0) && (loc.x >= drawable.right)) return; // exit early if completely clipped
	if (((style & Graphics::textStyle_RightJustified) == Graphics::textStyle_RightJustified) && (loc.x <= drawable.left)) return; // exit early if completely clipped
	// further checks require font info
	FontImpl* font = dynamic_cast<FontImpl*> ( getCurrentFont(style) );
	if (!font) return;
	Rect textRect;
	textRect.bottom = loc.y + std::ceil( font->getFontDescent(size, style) );
	if (textRect.bottom < drawable.top) return; // exit early if completely clipped
	textRect.top = loc.y - std::ceil( font->getFontAscent(size, style) );
	if (textRect.top > drawable.bottom) return; // exit early if completely clipped
	textRect.left = loc.x;

	// adjust for text justification
	int textwidth = getTextWidth(text, size, style, len);
	if (style & Graphics::textStyle_Centered) {
		textRect.left -= (textwidth/2);     // centered means the point given is the centerpoint for the text
	} else if (style & Graphics::textStyle_RightJustified) {
		textRect.left -= textwidth;         // otherwise the point given is the right-side end of the text
	}
	textRect.setWidth(textwidth);
	if (drawable.intersection(textRect).empty()) return; // exit early if completely clipped
#ifdef PDG_DEBUG_TEXT_DRAWING
	port.frameRect(textRect, PDG_MAGENTA_COLOR); // draw text bounding box
	port.drawLine(Point(textRect.left, loc.y), Point(textRect.right, loc.y), PDG_RED_COLOR); // draw baseline
#endif
	graphics_drawText(port, text, len, (Quad)textRect, size, style, rgba);
	port.mNeedRedraw = true;
	gPortDirty = true;
}
Esempio n. 3
0
/*****************************************************
**
**   Painter   ---   drawSingleMStringLine
**
******************************************************/
void Painter::drawSingleMStringLine( const MRect &r, MString &f, const int& align )
{
	assert( f.formattedLines.size() == 0 );
	wxString s;
	MPoint p;
	Lang lang( writercfg );
	wxFont oldFont = getCurrentFont();
	const int drawalign = Align::Left + Align::VCenter;
	SheetFormatter formatter( writercfg );

	if ( ! f.isEmpty() && ( f.size.real() == 0 ||  f.size.imag() == 0 ))
	{
		printf( "WARN: size not set\n" );
		f.size = getTextExtent( f );
	}

	//printf( "PAINT -- --- - - - - x %f y %f w %f h %f SIZE x %f y %f\n", r.x, r.y, r.width, r.height, size.real(), size.imag() );
	//printf( " ----- %s\n", str2char( formatter.fragment2PlainText( f )));

	double x0 = r.x;
	double y0 = r.y;

	if ( align & Align::HCenter )
	{
		x0 += .5 * ( r.width - f.size.real());
	}
	else if ( align & Align::Right )
	{
		x0 = x0 + r.width - f.size.real();
	}

	// offset for subscriptum and superscriptum
	const double yoffset = .5 * f.size.imag();

	double yy = y0; // + .5 * ( r.height - size.imag());
	for( list<MToken>::const_iterator iter = f.tokens.begin(); iter != f.tokens.end(); iter++ )
	{
		switch ( iter->fontFormat )
		{
			case TTFF_SUBSCRPTUM:
				yy = y0 + yoffset;
			break;
			case TTFF_SUPERSCRPTUM:
				yy = y0 - yoffset;
			break;
			case TTFF_NORMAL:
			default:
				yy = y0;
			break;
		}

		setFont( oldFont );

		wxChar symbol = 0;
		SymbolProvider sp( writercfg );
		switch ( iter->entity )
		{
			case TTSE_PLANET:
				if ( writercfg->planetSymbols ) symbol = sp.getPlanetCode( (ObjectId)iter->entityId );
				if ( ! symbol || symbol == SYMBOL_CODE_ERROR )
					s = formatter.getObjectNamePlain( (ObjectId)iter->entityId, iter->textFormat, iter->vedic );
			break;
			case TTSE_SIGN:
				if ( writercfg->signSymbols ) symbol = sp.getSignCode( (Rasi)iter->entityId );
				if ( ! symbol ) s = lang.getSignName( (Rasi)iter->entityId, iter->textFormat ); //, writercfg->vedicSignNames );
			break;
			case TTSE_ASPECT:
				symbol = SymbolProvider().getAspectCode( (ASPECT_TYPE)iter->entityId );
				if ( ! symbol ) s = AspectExpert::getAspectShortDescription( (int)iter->entityId );
			break;
			case TTSE_DIRECTION:
				symbol = sp.getRetroCode( (MOVING_DIRECTION)iter->entityId );
				if ( ! symbol ) s = wxT( "R" );
			break;
			default:
				symbol = 0;
				s = iter->text;
			break;
		}
		if ( symbol && symbol != SYMBOL_CODE_ERROR )
		{
			const int pointSize = oldFont.GetPointSize();
			setFont( *FontProvider::get()->getFontBySize( FONT_GRAPHIC_SYMBOLS, pointSize ));
			drawTextFormatted( MRect( x0, yy, r.width, r.height ), symbol, drawalign );
			p = getTextExtent( symbol );
		}
		else
		{
			drawTextFormatted( MRect( x0, yy, r.width, r.height ), s, drawalign );
			p = getTextExtent( s );
		}

		x0 += p.real();
	}
}