169 tResult
Create(
const cGLCanvas* ,
const char* strFilename, tInt nHeight,
tStyle eFontStyle)
171 if (g_hFreeTypeLibrary == NULL)
173 RETURN_ERROR(ERR_UNKNOWN);
176 char l_strFontPath[MAX_PATH];
179 char l_strWinDir[MAX_PATH];
180 char l_strPhysPath[MAX_PATH];
182 if (strchr(strFilename,
'.') != NULL)
184 adtf::util::cStringUtil::Copy(l_strPhysPath, strFilename, tSize(-1), tSize(MAX_PATH));
189 if (!_fnLookupFontFile(strFilename, l_strPhysPath))
191 adtf::util::cStringUtil::Copy(l_strPhysPath, strFilename, MAX_PATH - 5);
192 strcat_s(l_strPhysPath, MAX_PATH,
".ttf");
196 ::GetSystemWindowsDirectory(l_strWinDir,
sizeof(l_strWinDir));
197 sprintf_s(l_strFontPath, MAX_PATH,
"%s\\Fonts\\%s", l_strWinDir, l_strPhysPath);
201 FcPattern* psPat = FcNameParse((FcChar8*) strFilename);
202 FcConfigSubstitute(0, psPat, FcMatchPattern);
203 FcDefaultSubstitute(psPat);
205 FcFontSet* psFs = FcFontSetCreate();
207 FcPattern* psMatch = FcFontMatch(0, psPat, &sResult);
210 FcFontSetAdd(psFs, psMatch);
213 FcPatternDestroy(psPat);
216 if (psFs->nfont > 0 && FcPatternGetString(psFs->fonts[0], FC_FILE, 0, &strFile) == FcResultMatch)
218 adtf::util::cStringUtil::Copy(l_strFontPath, (
const tChar*) strFile, -1, MAX_PATH);
221 l_strFontPath[0] = 0;
223 FcFontSetDestroy(psFs);
227 l_nError = FT_New_Face(g_hFreeTypeLibrary, l_strFontPath, 0, &
m_hFace);
231 RETURN_ERROR(ERR_UNKNOWN);
241 RETURN_ERROR(ERR_MEMORY);
247 for (tInt c = 0; c < g_nCharsetSize; c++)
420 l_nError = FT_Load_Glyph(
m_hFace, FT_Get_Char_Index(
m_hFace, ch), FT_LOAD_DEFAULT);
423 RETURN_ERROR(ERR_UNKNOWN);
426 FT_Render_Mode l_nRenderMode;
431 l_nRenderMode = FT_RENDER_MODE_NORMAL;
436 l_nRenderMode = FT_RENDER_MODE_MONO;
441 l_nRenderMode = FT_RENDER_MODE_NORMAL;
446 l_nError = FT_Render_Glyph(
m_hFace->glyph, l_nRenderMode);
449 RETURN_ERROR(ERR_UNKNOWN);
452 FT_GlyphSlot slot =
m_hFace->glyph;
453 FT_Bitmap& bitmap = slot->bitmap;
458 int width = _fnGetNextPowerOfTwo(bitmap.width);
459 int height = _fnGetNextPowerOfTwo(bitmap.rows);
462 GLubyte* l_pTextureBuffer =
new GLubyte[2 * width * height];
465 if (bitmap.pixel_mode == FT_PIXEL_MODE_MONO)
469 for (
int j = 0; j < height; j++)
471 for (
int i = 0; i < width; i++)
473 if (i < bitmap.width && j < bitmap.rows)
475 l_nSrc = bitmap.buffer[i / 8 + bitmap.pitch * j];
476 l_nMask = (1 << (7 - (i % 8)));
477 l_nValue = ((l_nSrc & l_nMask) != 0) ? 255 : 0;
484 l_pTextureBuffer[2 * (i + j * width)] = l_pTextureBuffer[2 * (i + j * width) + 1] =
489 else if (bitmap.pixel_mode == FT_PIXEL_MODE_GRAY)
491 for (
int j = 0; j < height; j++)
493 for (
int i = 0; i < width; i++)
495 if (i < bitmap.width && j < bitmap.rows)
497 l_nValue = bitmap.buffer[i + bitmap.pitch * j];
504 l_pTextureBuffer[2 * (i + j * width)] = l_pTextureBuffer[2 * (i + j * width) + 1] =
511 RETURN_ERROR(ERR_NOT_SUPPORTED);
514 glEnable(GL_TEXTURE_2D);
517 glBindTexture(GL_TEXTURE_2D,
m_hTextures[
static_cast<tInt
>(ch)]);
518 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
519 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
520 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
521 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
526 gluBuild2DMipmaps(GL_TEXTURE_2D, 2, width, height, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, l_pTextureBuffer);
529 delete[] l_pTextureBuffer;
533 glBindTexture(GL_TEXTURE_2D,
m_hTextures[
static_cast<tInt
>(ch)]);
539 glTranslatef((GLfloat) slot->bitmap_left, 0.0f, 0.0f);
544 glTranslatef(0.0f, (GLfloat) bitmap.rows - slot->bitmap_top, 0.0f);
553 float u = (float) bitmap.width / (
float) width;
554 float v = (float) bitmap.rows / (
float) height;
562 tInt cx = bitmap.width;
563 tInt cy = bitmap.rows;
565 tInt l_nFontHeight = ((slot->metrics.vertAdvance + 63) / 64);
568 glNormal3f(0.0f, 0.0f, -1.0f);
570 glVertex2i(0, l_nFontHeight - cy - 1);
572 glVertex2i(0, l_nFontHeight - 1);
574 glVertex2i(cx, l_nFontHeight - 1);
576 glVertex2i(cx, l_nFontHeight - cy - 1);
580 glTranslatef((GLfloat) (
m_hFace->glyph->advance.x) / 64.0f, 0.0f, 0.0f);
590 glDisable(GL_TEXTURE_2D);
605 void PrintImpl(tUInt32 ui32Flags, tFloat32 x, tFloat32 y, tFloat64 fAngle,
const char* strFormat, va_list ArgList)
607 tBool bUseIntCoords = (ui32Flags != 0);
610 tFloat32 fLineHeight = (tFloat32)
m_nHeight / 0.63f;
611 tChar strBuffer[4096];
613 if (strFormat == NULL)
620 vsprintf_s(strBuffer, 4096, strFormat, ArgList);
622 vsprintf(strBuffer, strFormat, ArgList);
626 const char* start_line = strBuffer;
627 std::vector<std::string> lines;
629 for (ptr = strBuffer; *ptr !=
'\0'; ptr++)
634 for (
const tChar* ptr2 = start_line; ptr2 < ptr; ptr2++)
636 line.append(1, *ptr2);
639 lines.push_back(line);
641 start_line = ptr + 1;
648 for (
const tChar* ptr2 = start_line; ptr2 < ptr; ptr2++)
650 line.append(1, *ptr2);
653 lines.push_back(line);
656 glPushAttrib(GL_LIST_BIT | GL_CURRENT_BIT | GL_ENABLE_BIT | GL_TRANSFORM_BIT);
657 glMatrixMode(GL_MODELVIEW);
658 glEnable(GL_TEXTURE_2D);
662 if (!glIsEnabled(GL_BLEND))
665 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
674 glTranslated(x, y, 0.0);
676 if (!m_bScaleWithCoordinateSystem || !m_bRotationWithCoordinateSystem)
680 GLdouble modelview[16];
681 glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
684 GLdouble fScaleX = sqrt(modelview[0] * modelview[0] + modelview[4] * modelview[4]);
686 GLdouble fScaleY = sqrt(modelview[1] * modelview[1] + modelview[5] * modelview[5]);
689 glTranslated(modelview[12], modelview[13], modelview[14]);
691 if (m_bRotationWithCoordinateSystem)
694 GLdouble fRotation = atan2(modelview[1] / fScaleX, modelview[0] / fScaleY);
696 glRotated(fRotation / M_PI * 180, 0, 0, 1);
699 if (m_bScaleWithCoordinateSystem)
702 glScaled(fScaleX, fScaleY, 0.0);
706 if (!m_bOpposedYAxis)
709 glRotated(180.0, 1.0, 0.0, 0.0);
713 glRotated(fAngle, 0.0, 0.0, 1.0);
719 for (
int i = 0; i < (int) lines.size(); i++)
721 const tChar* strLine = lines[i].c_str();
722 tInt nLineLen = (tInt) lines[i].length();
725 int iLineCorrection = m_bTextBaselineOnTop ? 0 :
static_cast<int>(lines.size());
726 GLdouble fLineOffset = (fLineHeight * (i - iLineCorrection)) *
m_nTextureScale / 64;
730 fLineOffset =
static_cast<GLdouble
>(
static_cast<tInt
>(fLineOffset));
735 glTranslated(0.0, fLineOffset, 0.0);
738 glCallLists(nLineLen, GL_UNSIGNED_BYTE, strLine);
777 nResult = RegEnumValue(hKey, nIdx, strValueBuffer, &dwValueBufferSize, NULL, &dwType, (BYTE*) strDataBuffer,