Vector2I GUIInputCaret::getCaretPosition(const Vector2I& offset) const
	{
		if(mNumChars > 0 && isDescValid())
		{
			UINT32 curPos = 0;
			UINT32 numLines = getNumLines();

			for(UINT32 i = 0; i < numLines; i++)
			{
				const GUIInputLineDesc& lineDesc = getLineDesc(i);

				if(mCaretPos == curPos)
				{
					// Caret is on line start
					return Vector2I(offset.x, lineDesc.getLineYStart() + getTextOffset().y);
				}

				curPos += lineDesc.getEndChar(false) - lineDesc.getStartChar() + 1; // + 1 for special line start position
			}

			UINT32 charIdx = getCharIdxAtCaretPos();
			if(charIdx > 0)
				charIdx -= 1;			

			charIdx = std::min((UINT32)(mNumChars - 1), charIdx);

			Rect2I charRect = getCharRect(charIdx);
			UINT32 lineIdx = getLineForChar(charIdx);
			UINT32 yOffset = getLineDesc(lineIdx).getLineYStart() + getTextOffset().y;

			return Vector2I(charRect.x + charRect.width, yOffset);
		}

		return offset;
	}
Exemple #2
0
/**
* CBitmapFont::drawStringMarkup
* @date Modified Mar 29, 2006
*/
void CBitmapFont::drawStringMarkup(CString str, float fX, float fY, D3DCOLOR dwColor, bool bHandleSprite)
{
	CRenderDevice& oDev = CRenderSystem::getInstance().getRenderDevice();
	LPD3DXSPRITE pSprite = oDev.getD3DXSprite();
	RECT rChar;
	char cChar;
	D3DXVECTOR3 vPos, vZero;
	vPos.x = fX;
	vPos.y = fY;
	vPos.z = 0.0f;
	vZero.x = vZero.y = vZero.z = 0.0f;

	if(bHandleSprite)
		beginSprite();

	// Split strings
	bool bFirst = false;
	std::vector<CString> vStrings;
	str.ToList(vStrings, TEXT("{}"));
	if(str.GetChar(0) == '{')
		bFirst = true;

	// Iterate split strings, and change color if needed.
	for(size_t v = 0; v < vStrings.size(); ++v)
	{
		// Get string, and read color
		if((bFirst && v % 2 == 0) || (!bFirst && v % 2 == 1))
		{
			dwColor = vStrings[v].ToUlongFromHex();
			continue;						   
		}

		// Iterate string and draw characters.
		size_t nSize = vStrings[v].GetLength();
		for(size_t i = 0; i < nSize; ++i)
		{
			cChar = vStrings[v].GetChar(i);
			switch(cChar)
			{
			case '\n':
				vPos.y += m_cLineHeight;
				vPos.x = fX;
				break;
			case '\t':
				vPos.x += m_mCharMap['X'] * 4;
				break;
			default:
				getCharRect(cChar, &rChar);
				pSprite->Draw(m_poTexture->getD3DTexture(), &rChar, NULL, &vPos, dwColor);
				vPos.x += (rChar.right - rChar.left);
				break;
			}
		}
	}

	if(bHandleSprite)
		endSprite();
}
	void GUIInputCaret::moveCaretToPos(const Vector2I& pos)
	{
		INT32 charIdx = getCharIdxAtPos(pos);

		if(charIdx != -1)
		{
			Rect2I charRect = getCharRect(charIdx);

			float xCenter = charRect.x + charRect.width * 0.5f;
			if(pos.x <= xCenter)
				moveCaretToChar(charIdx, CARET_BEFORE);
			else
				moveCaretToChar(charIdx, CARET_AFTER);
		}
		else
		{
			UINT32 numLines = getNumLines();

			if(numLines == 0)
			{
				mCaretPos = 0;
				return;
			}

			UINT32 curPos = 0;
			for(UINT32 i = 0; i < numLines; i++)
			{
				const GUIInputLineDesc& line = getLineDesc(i);

				INT32 lineStart = line.getLineYStart() + getTextOffset().y;
				if(pos.y >= lineStart && pos.y < (lineStart + (INT32)line.getLineHeight()))
				{
					mCaretPos = curPos;
					return;
				}

				UINT32 numChars = line.getEndChar(false) - line.getStartChar() + 1; // +1 For extra line start position
				curPos += numChars;
			}

			{
				const GUIInputLineDesc& firstLine = getLineDesc(0);
				INT32 lineStart = firstLine.getLineYStart() + getTextOffset().y;

				if(pos.y < lineStart) // Before first line
					mCaretPos = 0;
				else // After last line
					mCaretPos = curPos - 1;
			}
		}
	}
Exemple #4
0
/**
* CBitmapFont::drawString
* @date Modified Mar 29, 2006
*/
void CBitmapFont::drawString(CString str, float fX, float fY, D3DCOLOR dwColor, bool bHandleSprite)
{
	CRenderDevice& oDev = CRenderSystem::getInstance().getRenderDevice();
	LPD3DXSPRITE pSprite = oDev.getD3DXSprite();

	RECT rChar;
	char cChar;
	D3DXVECTOR3 vPos, vZero;
	vPos.x = fX;
	vPos.y = fY;
	vPos.z = 0.0f;
	vZero.x = vZero.y = vZero.z = 0.0f;

	if(bHandleSprite)
		beginSprite();

	// Iterate string and draw characters.
	size_t nSize = str.GetLength();
	for(size_t i = 0; i < nSize; ++i)
	{
		cChar = str.GetChar(i);
		switch(cChar)
		{
		case '\n':
			vPos.y += m_cLineHeight;
			vPos.x = fX;
			break;
		case '\t':
			vPos.x += m_mCharMap['X'] * 4;
			break;
		default:
			getCharRect(str.GetChar(i), &rChar);
			pSprite->Draw(m_poTexture->getD3DTexture(), &rChar, NULL, &vPos, dwColor);
			vPos.x += (rChar.right - rChar.left);
			break;
		}
	}

	if(bHandleSprite)
		endSprite();
}
void TiledFont::process_image() {
	Size s = m_img->GetImageSize();
	int tw = m_tilesize.w;
	int th = m_tilesize.h;
	row_tiles = s.w / tw;
	int rows = s.h / th;
	n_tiles = row_tiles * rows;
	m_char_rect.resize(n_tiles);
	
	int space_tile = m_char_index[' '];
	
	int tile=0;
	for(int row = 0; row < rows; row++) {
		for(int col = 0; col < row_tiles; col++) {
			Rect o(col*m_tilesize.w, row*m_tilesize.h, m_tilesize.w, m_tilesize.h);
			
			if(!m_monosize && tile != space_tile) {
				
				Rect r;
				
				const unsigned int* pixels = m_img->GetImage();
				int ylen = (row+1)*th;
				int xlen = (col+1)*tw;
				for(int y = row*th; y < ylen; ++y) {
					for(int x = col*tw; x < xlen; ++x) {
						const unsigned int &p = pixels[y*s.w+x];
						if((p&0xffffff) != m_bg_key) {
							r.y = y;
							goto j1;
							break;
						}
					}
				}
				j1:
				
				ylen = row*th;
				xlen = (col+1)*tw;
				for(int y = (row+1)*th-1; y > ylen; --y) {
					for(int x = col*tw; x < xlen; ++x) {
						const unsigned int &p = pixels[y*s.w+x];
						if((p&0xffffff) != m_bg_key) {
							r.h = y-r.y;
							goto j2;
							break;
						}
					}
				}
				j2:
				
				xlen = (col+1)*tw;
				ylen = (row+1)*th;
				for(int x = col*tw; x < xlen; ++x) {
					for(int y = row*th; y < ylen; ++y) {
						const unsigned int &p = pixels[y*s.w+x];
						if((p&0xffffff) != m_bg_key) {
							r.x = x;
							goto j3;
							break;
						}
					}
				}
				j3:
				
				
				xlen = (col)*tw;
				ylen = (row+1)*th;
				for(int x = (col+1)*tw-1; x > xlen; --x) {
					for(int y = (row)*th; y < ylen; ++y) {
						const unsigned int &p = pixels[y*s.w+x];
						if((p&0xffffff) != m_bg_key) {
							r.w = x-r.x;
							goto j4;
							break;
						}
					}
				}
				j4:
				r.x--;
				if(r.x < 0) r.x = 0;
				r.w+=2;
				r.y--;
				if(r.y < 0) r.y = 0;
				r.h+=2;
				o = r;
			
			
				// std::cout << "letter: " << (int)tile << " : " << o << "\n";
				// if(r.w == 0 || r.h == 0) {
					// exit(-1);
				// }
				
				// o.w = r.w;
				// o.h = r.h;
				// o.x = r.x;
				// o.y = r.y;
			}
			
			m_char_rect[tile] = o;
			tile++;
		}
	}
	
	Rect r = getCharRect('a');
	
	Rect space_rect = getCharRect(' ');
	tile = m_char_index[' '];
	
	int tile_y = tile / row_tiles;
	int tile_x = tile % row_tiles;
	// r.x = tw / 4;
	// r.y = th / 4;
	space_rect.w = r.w;
	space_rect.h = r.h;
	// std::cout << "space rect: " << space_rect.x << ", " << space_rect.y << " => " << space_rect.x/tw << ", " << space_rect.y/th << "\n";
	
	setCharRect(' ', space_rect);
	// m_char_rect[ tile ] = space_rect;
}
Exemple #6
0
/**
 * OCR process from gray image input
 */
int ocrProcess(Image binImg) {

    int i, h, w;
    h = binImg.h;
    w = binImg.w;
    int count =0, lCount = 0;

    int start = 0;
    int endLine = 0;
    int nLine;
    Rect rect;

    int* charIndex[20];

    system("rm -rf data");
    system("mkdir -p data");
    system("rm -rf leven");
    system("mkdir -p leven");


    createNetworkFromFile();

    /// segmentation processing
    while((nLine = ccLineLabeling(binImg, start))!= 0) {
        if(nLine < 3) continue;
        printf("%d\n",nLine);
        int baseLine = getBaselineHeight(nLine);

//        int avgSpace = getAverageSpace(nLine);
        /// get slant deg
        int slantDeg = getSlantDeg(binImg, baseLine, nLine);
//        printf("slantDeg = %d\n", slantDeg);

        int nChar = 0;

        for(i = 0; i < nLine; i++) {
            int index = getSegmentIndex(i);
//            printf("%d ", index);
            rect = getCharRect(index);
            endLine = endLine > (rect.y + rect.h) ? endLine :(rect.y + rect.h);
            Image charImg = getImageFromRect(binImg, rect, index);
            if(slantDeg) {
                charImg = slantRemoval(charImg, slantDeg);
            }
//            char* name = (char*) malloc(20* sizeof(char));
//            sprintf(name, "out_s_%d_%d.txt", lCount, i);
//            printImage(charImg, name);

            charImg = contourFinding(charImg);
            smoothContour(charImg);
            thinImageOnMatch(charImg);
            double* input = getFeature(charImg);
            double prop, maxProp = 0.0;

            /// recognition
            nChar++;
            charIndex[nChar-1] = charRecognition(input, &prop);


            /// check space
            //int space = getSpace(i, nLine, binImg);
            //if(space > baseLine/2) {//printf(" ");
            //    createWordFst(charIndex, nChar);
            //    nChar = 0;
            //    printf(" ");
            //}
            deleteImage(charImg);
            free(input);
            count++;
//            }
//            printf(" ");
//            start_w = end_w;
//            deleteImage(wordImg);
        }
        printf("\n");
        start = endLine;
        lCount++;
    }
    deleteImage(binImg);
    deleteNetwork();
    printf("%d\n", count);
    return 0;
}