Beispiel #1
0
int BdfFont::getCharWidth(uint32 chr) const {
	// In case all font have the same advance value, we use the maximum.
	if (!_data.advances)
		return _data.maxAdvance;

	const int ch = mapToIndex(chr);
	// In case no mapping exists, we use the maximum advance.
	if (ch < 0)
		return _data.maxAdvance;
	else
		return _data.advances[ch];
}
Beispiel #2
0
void BdfFont::drawChar(Surface *dst, uint32 chr, const int tx, const int ty, const uint32 color) const {
	assert(dst != 0);

	// TODO: Where is the relation between the max advance being smaller or
	// equal to 50 and the decision of the theme designer?
	// asserting _data.maxAdvance <= 50: let the theme designer decide what looks best
	assert(_data.maxAdvance <= 50);
	assert(dst->getFormat().bytesPerPixel == 1 || dst->getFormat().bytesPerPixel == 2 || dst->getFormat().bytesPerPixel == 4);

	const int idx = mapToIndex(chr);
	if (idx < 0)
		return;

	int width, height, xOffset, yOffset;

	// Get the bounding box of the character
	if (!_data.boxes) {
		width = _data.defaultBox.width;
		height = _data.defaultBox.height;
		xOffset = _data.defaultBox.xOffset;
		yOffset = _data.defaultBox.yOffset;
	} else {
		width = _data.boxes[idx].width;
		height = _data.boxes[idx].height;
		xOffset = _data.boxes[idx].xOffset;
		yOffset = _data.boxes[idx].yOffset;
	}

	int y = ty + _data.ascent - yOffset - height;
	int x = tx + xOffset;

	const byte *src = _data.bitmaps[idx];

	const int bytesPerRow = (width + 7) / 8;
	const int originalWidth = width;

	// Make sure we do not draw outside the surface
	if (y < 0) {
		src -= y * bytesPerRow;
		height += y;
		y = 0;
	}

	if (y + height > dst->getHeight())
		height = dst->getHeight() - y;

	if (height <= 0)
		return;

	int xStart = 0;
	if (x < 0) {
		xStart = -x;
		width += x;
		x = 0;
	}

	if (x + width > dst->getWidth())
		width = dst->getWidth() - x;

	if (width <= 0)
		return;

	const int xEnd = xStart + width - 1;

	byte *ptr = (byte *)dst->getBasePtr(x, y);

	if (dst->getFormat().bytesPerPixel == 1)
		drawCharIntern<byte>(ptr, dst->getPitch(), src, height, originalWidth, xStart, xEnd, color);
	else if (dst->getFormat().bytesPerPixel == 2)
		drawCharIntern<uint16>(ptr, dst->getPitch(), src, height, originalWidth, xStart, xEnd, color);
	else if (dst->getFormat().bytesPerPixel == 4)
		drawCharIntern<uint32>(ptr, dst->getPitch(), src, height, originalWidth, xStart, xEnd, color);
}
Beispiel #3
0
int QHeader::cellAt( int pos ) const
{
    return mapToIndex( sectionAt(pos + offset()) );
}