Beispiel #1
0
	void Font::drawBoundedString(const char* strS, int x, int y, const Rect& bound) {
		int i = 0;
		int j = 0;
		if(!mFontImage) return;
		const unsigned char* str = (const unsigned char*)strS;
		calcLineBreaks(strS, x, y, bound);
		MARect srcRect = {0, 0, 0, 0};
		MAPoint2d cursor = {x, y};
		CharDescriptor *chars = mCharset->chars;
		while(str[i]) {
			if(lineBreaks[j] == i) {
				j++;
				cursor.x = x;
				cursor.y += mCharset->lineHeight + mLineSpacing;
				if(str[i]=='\n') {
					i++;
					continue;
				}
			}

			srcRect.left = chars[str[i]].x;
			srcRect.top = chars[str[i]].y;
			srcRect.width = chars[str[i]].width;
			srcRect.height = chars[str[i]].height;

			MAPoint2d destPoint = {cursor.x + chars[str[i]].xOffset,
				cursor.y + chars[str[i]].yOffset};

			//maDrawImageRegion(this->mFontImage, &srcRect, &destPoint, 0);
			Gfx_drawImageRegion(this->mFontImage, &srcRect, &destPoint, 0);

			cursor.x += chars[str[i]].xAdvance;
			i++;
		}
	}
Beispiel #2
0
	MAExtent Font::getBoundedStringDimensions(
		const char *strS,
		const Rect &bound,
		int length) const
	{
		if(length == 0) {
			return EXTENT(0, 0);
		}
		if(!mFontImage) {
			return EXTENT(0, 0);
		}

		calcLineBreaks(strS, bound.x, bound.y, bound);

		int i = 0;
		int j = 0;
		//MARect srcRect = {0, 0, 0, 0};
		MAPoint2d cursor = {0, 0};
		int height = 0;
		int width = 0;
		CharDescriptor *chars = mCharset->chars;
		const unsigned char* str = (const unsigned char*)strS;

		while(*str && (i!=length)) {
			if((lineBreaks[j] == i) || ((*str) == '\n')) {
				j++;
				cursor.x = 0;
				cursor.y += mCharset->lineHeight + mLineSpacing;
				str++;
				i++;
				continue;
			}
			else {
				cursor.x += chars[*str].xAdvance;
			}

			// TODO: Clean up formatting, remove commented out code.
			if(cursor.y + mCharset->lineHeight//mCharset.chars[*str].yOffset + mCharset.chars[*str].height
			> height) {
				//height = (cursor.y + mCharset.chars[*str].yOffset + mCharset.chars[*str].height);
				height = cursor.y + mCharset->lineHeight;
			}

			// TODO: Clean up formatting, remove commented out code.
			if(cursor.x//mCharset.chars[*str].xOffset + mCharset.chars[*str].width
			> width) {
				//width = (cursor.x + mCharset.chars[*str].xOffset + mCharset.chars[*str].width);
				width = cursor.x; //cursor.x + mCharset.chars[*str].xAdvance;
			}


			str++;
			i++;
		}
		return EXTENT(width, height);
	}
Beispiel #3
0
	int Font::calculateLine(int index, const char *str, const Rect& bound) const {
		calcLineBreaks(str, bound.x, bound.y, bound);
		//short *ptrLineBreaks = lineBreaks;
		int i = 0;
		for(i = 0; i < numLineBreaks; i++) {
			if(index<=lineBreaks[i]) {
				return i;
			}
		}
		return i;
	}
Beispiel #4
0
	int Font::getLineBreak(
		int line,
		const char *str,
		const Rect& bound) const
	{
		calcLineBreaks(str, bound.x, bound.y, bound);
		if(line < 0 || line >= numLineBreaks) {
			return -1;
		}
		else {
			return lineBreaks[line];
		}
	}