2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FGrp_FontFt2.cpp
20 * @brief This is the implementation file for _FontFt2 class.
27 #include <unique_ptr.h>
30 #include <freetype/tttables.h>
31 #include FT_FREETYPE_H
34 #include <FBaseErrors.h>
36 #include <FBaseSysLog.h>
37 #include <FBaseUtilStringUtil.h>
38 #include <FBaseColIHashCodeProviderT.h>
40 #include "FGrp_FontFt2.h"
41 #include "FGrp_FontCache.h"
42 #include "FGrp_FontBidiUtil.h"
43 #include "util/FGrp_UtilTemplate.h"
44 #include "util/FGrp_UtilType.h"
46 #define CHECK_NULL_PARAM(data) if (data == null) \
51 using namespace Tizen::Base;
52 using namespace Tizen::Base::Collection;
53 using namespace Tizen::Graphics;
57 const double _M_PI = 3.14159265358979323846;
58 const double _ITALIC_ANGLE = 10.619655;
59 const _Util::FixedPoint26_6 _SYSTEM_DEFAULT_FONT_SIZE(16);
60 const long _DEFAULT_RES = 72;
62 const unsigned long _INDEX_FIRST = 32; // in first resource, the first chracter(space)
63 const unsigned long _INDEX_COUNT = 95; // first resource character count
65 const long _MEDIUM_FONT_BOLD_WEIGHT = 600;
68 _CompareFamilyForTitling(const char* pFamilyName)
70 static const char* _compNames[] =
72 "TitlingGothicFB Comp",
73 "TitlingGothicFB Cond",
74 "TitlingGothicFB Narrow",
75 "TitlingGothicFB Skyline"
78 for (unsigned int i = 0; i < sizeof(_compNames) / sizeof(_compNames[0]); i++)
80 if (strcmp(pFamilyName, _compNames[i]) == 0)
89 #ifdef USE_HASHMAP_FOR_FONT
91 class _FontHashCodeProvider
92 : public IHashCodeProviderT <T>
95 virtual int GetHashCode(const T& obj) const
97 return obj.GetHashCode();
99 }; // _FontHashCodeProvider
103 : public IComparerT <T>
106 virtual result Compare(const T& obj1, const T& obj2, int& cmp) const
108 String& objString1 = static_cast <String&>(const_cast <T&>(obj1));
109 String& objString2 = static_cast <String&>(const_cast <T&>(obj2));
111 cmp = objString1.CompareTo(objString2);
118 class _FontHashCodeProviderEx
119 : public IHashCodeProviderT <T>
122 virtual int GetHashCode(const T& obj) const
124 const wchar_t* pText = obj.c_str();
125 const wchar_t* pTextEnd = pText - 1;
127 while (*(++pTextEnd))
130 int stride = ((pTextEnd - pText + 1) << 16) / 9;
133 int ret1 = (pText[(ix16 += stride) >> 16] & 0xFF);
134 ret1 |= ((pText[(ix16 += stride) >> 16] & 0xFF) << 8);
135 ret1 |= ((pText[(ix16 += stride) >> 16] & 0xFF) << 16);
136 ret1 |= ((pText[(ix16 += stride) >> 16] & 0xFF) << 24);
138 int ret2 = (pText[(ix16 += stride) >> 16] & 0xFF);
139 ret2 |= ((pText[(ix16 += stride) >> 16] & 0xFF) << 8);
140 ret2 |= ((pText[(ix16 += stride) >> 16] & 0xFF) << 16);
141 ret2 |= ((pText[(ix16 += stride) >> 16] & 0xFF) << 24);
145 }; // _FontHashCodeProviderEx
148 class _FontComparerEx
149 : public IComparerT <T>
152 virtual result Compare(const T& obj1, const T& obj2, int& cmp) const
154 cmp = wcscmp((wchar_t*)obj1.c_str(), (wchar_t*)obj2.c_str());
158 }; // _FontComparerEx
160 const _FontHashCodeProviderEx<_Util::WString> _fontHashCodeProviderEx;
161 const _FontComparerEx<_Util::WString> _fontComparerEx;
165 namespace Tizen { namespace Graphics
169 _IsEqual(float f1, float f2)
171 return (((f1 > f2) ? f1 - f2 : f2 - f1) < 0.00001f); // epsilon is assumed to be 0.0001, not 1.192092896e-07f
176 , __isLoadGlyph(false)
177 , __pFontEngine(null)
179 , __pFontBuffer(null)
180 , __isStaticBuffer(false)
183 __fontAttrib.size = _SYSTEM_DEFAULT_FONT_SIZE;
184 __fontAttrib.angle = 0.0f;
185 __fontAttrib.style = _IFont::STYLE_NONE;
186 __fontAttrib.quality = _IFont::QUALITY_HIGH;
187 __fontAttrib.xExpansion = 100;
188 __fontAttrib.boldWeight = _Util::FixedPoint26_6(1.0f);
190 #ifdef USE_HASHMAP_FOR_FONT
191 __fallbackFontMap.Construct(1, 0, _fontHashCodeProviderEx, _fontComparerEx);
195 __fontCache.reset(new (std::nothrow) _FontCache());
198 _FontFt2::~_FontFt2()
208 #ifdef USE_HASHMAP_FOR_FONT
209 __fallbackFontMap.RemoveAll();
211 __fallbackFontMap.clear();
216 _FontFt2::Create(const void* pBuffer, long bufSize, long face)
223 int error = FT_Init_FreeType(static_cast<FT_Library*>((void*) &__pFontEngine));
232 // should keep the buffer
233 __pFontBuffer = new (std::nothrow) byte[bufSize];
242 memcpy(__pFontBuffer, pBuffer, bufSize);
244 error = FT_New_Memory_Face(FT_Library(__pFontEngine), (const byte*) __pFontBuffer, bufSize, face, static_cast<FT_Face*>((void*) &__pFontFace));
253 FT_Face pFace = FT_Face(__pFontFace);
255 if ((pFace->charmap == null) && (pFace->num_charmaps > 0))
257 FT_Set_Charmap(pFace, pFace->charmaps[0]);
268 _FontFt2::Create(const char* pFilePath, long face)
275 int error = FT_Init_FreeType(static_cast<FT_Library*>((void*) &__pFontEngine));
284 error = FT_New_Face(FT_Library(__pFontEngine), pFilePath, face, static_cast<FT_Face*>((void*) &__pFontFace));
293 FT_Face pFace = FT_Face(__pFontFace);
295 if ((pFace->charmap == null) && (pFace->num_charmaps > 0))
297 FT_Set_Charmap(pFace, pFace->charmaps[0]);
308 _FontFt2::CreateStatic(const void* pBuffer, long bufSize, long face)
315 FT_Face pFace = null;
317 int error = FT_Init_FreeType(static_cast<FT_Library*>((void*) &__pFontEngine));
326 __pFontBuffer = const_cast<void*>(pBuffer);
327 __isStaticBuffer = true;
329 error = FT_New_Memory_Face(FT_Library(__pFontEngine), (const byte*) __pFontBuffer, bufSize, face, static_cast<FT_Face*>((void*) &__pFontFace));
338 pFace = FT_Face(__pFontFace);
340 if ((pFace->charmap == null) && (pFace->num_charmaps > 0))
342 FT_Set_Charmap(pFace, pFace->charmaps[0]);
353 _FontFt2::Reload(const void* pBuffer, long bufSize, long face)
360 std::unique_ptr<byte[]> pReloadBuffer(new (std::nothrow) byte[bufSize]);
362 if (pReloadBuffer == null)
367 memcpy(pReloadBuffer.get(), pBuffer, bufSize);
369 void* pReloadFace = null;
371 int error = FT_New_Memory_Face(FT_Library(__pFontEngine), (const byte*) pReloadBuffer.get(), bufSize, face, static_cast<FT_Face*>((void*) &pReloadFace));
381 FT_Done_Face(FT_Face(__pFontFace));
385 if (__pFontBuffer && !__isStaticBuffer)
387 delete[] static_cast<byte*>(__pFontBuffer);
390 // assign new resource
391 __pFontBuffer = pReloadBuffer.release();
392 __pFontFace = pReloadFace;
393 __isStaticBuffer = false;
395 FT_Face pFace = FT_Face(__pFontFace);
397 if ((pFace->charmap == null) && (pFace->num_charmaps > 0))
399 FT_Set_Charmap(pFace, pFace->charmaps[0]);
410 _FontFt2::Reload(const char* filePath, long face)
417 void* pReloadFace = null;
419 int error = FT_New_Face(FT_Library(__pFontEngine), filePath, face, static_cast<FT_Face*>((void*) &pReloadFace));
429 FT_Done_Face(FT_Face(__pFontFace));
433 // assign new resource
434 __pFontFace = pReloadFace;
435 __isStaticBuffer = false;
437 FT_Face pFace = FT_Face(__pFontFace);
439 if ((pFace->charmap == null) && (pFace->num_charmaps > 0))
441 FT_Set_Charmap(pFace, pFace->charmaps[0]);
452 _FontFt2::Destroy(void)
464 _FontFt2::FindCache(unsigned long glyphIndex, _Util::FixedPoint26_6 size, int style, Glyph** pOut)
466 return (__fontCache.get()) ? __fontCache->Find(glyphIndex, __fontAttrib.size, __fontAttrib.style, pOut) : false;
470 _FontFt2::AddCache(unsigned long glyphIndex, _Util::FixedPoint26_6 size, int style, Glyph* pGlyph)
472 return (__fontCache.get()) ? __fontCache->Add(glyphIndex, size, style, pGlyph) : false;
476 _FontFt2::CleanCache()
478 return (__fontCache.get()) ? __fontCache->Cleanup() : false;
482 _FontFt2::SetAttrib(const Attrib& fontAttrib)
489 if (!(fontAttrib.size >= 1) ||
490 !(fontAttrib.quality >= 0 && fontAttrib.quality <= 3) ||
491 !(fontAttrib.xExpansion >= 1) ||
492 !(fontAttrib.size.ToInt() * fontAttrib.xExpansion >= _DEFAULT_RES) ||
493 !(fontAttrib.boldWeight > 0))
498 if (FT_IS_SCALABLE(FT_Face(__pFontFace)) == 0)
503 if (__fontAttrib.size != fontAttrib.size)
505 if (FT_Set_Char_Size(FT_Face(__pFontFace), fontAttrib.size.__fixedPoint * _DEFAULT_RES, fontAttrib.size.__fixedPoint * _DEFAULT_RES, 1, 1) > 0)
512 memcpy(&__fontAttrib, &fontAttrib, sizeof(fontAttrib));
518 _FontFt2::GetAttrib(Attrib& fontAttrib) const
525 fontAttrib.angle = __fontAttrib.angle;
526 fontAttrib.quality = __fontAttrib.quality;
527 fontAttrib.size = __fontAttrib.size;
528 fontAttrib.style = __fontAttrib.style;
529 fontAttrib.xExpansion = __fontAttrib.xExpansion;
530 fontAttrib.boldWeight = __fontAttrib.boldWeight;
536 _FontFt2::GetKerning(unsigned long character1, unsigned long character2, long& xVector, long& yVector) const
543 bool isCharacter1InEnglish = false;
544 bool isCharacter2InEnglish = false;
545 FT_Face pFace = null;
546 unsigned long index1 = 0;
547 unsigned long index2 = 0;
549 if (character1 >= _INDEX_FIRST && character1 < (_INDEX_FIRST + _INDEX_COUNT))
551 isCharacter1InEnglish = true;
554 if (character2 >= _INDEX_FIRST && character2 < (_INDEX_FIRST + _INDEX_COUNT))
556 isCharacter2InEnglish = true;
559 if (isCharacter1InEnglish != isCharacter2InEnglish)
566 pFace = FT_Face(__pFontFace);
567 index1 = __GetGlyphIndex(character1);
568 index2 = __GetGlyphIndex(character2);
570 bool hasKerning = false;
572 hasKerning = (FT_HAS_KERNING(pFace) != 0);
578 int isSuccess = FT_Get_Kerning(pFace, index1, index2, ft_kerning_default, &delta);
580 if (isSuccess != 0) //0 means success.
585 _Util::FixedPoint26_6 deltaX;
586 _Util::FixedPoint26_6 deltaY;
588 deltaX.Reset(delta.x);
589 deltaY.Reset(delta.y);
591 xVector = deltaX.ToInt();
592 yVector = deltaY.ToInt();
604 _FontFt2::LoadGlyph(unsigned long character, Glyph** ppFontGlyphData)
611 CHECK_NULL_PARAM(__pFontFace);
612 CHECK_NULL_PARAM(ppFontGlyphData);
614 FT_UInt glyphIndex = __GetGlyphIndex(character);
616 bool rtn = FindCache(glyphIndex, __fontAttrib.size, __fontAttrib.style, ppFontGlyphData);
623 *ppFontGlyphData = null;
625 FT_Face pFace = null;
627 pFace = FT_Face(__pFontFace);
629 if (!FT_IS_SCALABLE(pFace))
631 SysLog(NID_GRP, "[] FT_IS_SCALABLE has been failed");
634 // set transformation
636 FT_Vector pen = {0, 0};
637 __SetTransMatrix(&matrix);
638 FT_Set_Transform(pFace, &matrix, &pen);
640 if (__fontAttrib.quality == _IFont::QUALITY_LOW ||
641 __fontAttrib.quality == _IFont::QUALITY_MEDIUM ||
642 __fontAttrib.quality == _IFont::QUALITY_HIGH)
644 FT_Error errCode = 1;
646 bool isSynthetic = (__fontAttrib.style & _IFont::STYLE_BOLD) && (__fontProperty.weightClass < _MEDIUM_FONT_BOLD_WEIGHT);
650 errCode = FT_Load_Glyph(pFace, glyphIndex, FT_LOAD_DEFAULT | FT_LOAD_NO_BITMAP);
654 //errCode = FT_Load_Glyph(pFace, glyphIndex, FT_LOAD_RENDER);
655 errCode = FT_Load_Glyph(pFace, glyphIndex, FT_LOAD_DEFAULT);
658 if (errCode) // 0: success
660 SysLogException(NID_GRP, E_SYSTEM, "[E_SYSTEM] FT_Load_Glyph_HighQuality(errCode = %#x)=", errCode);
667 FT_Outline_Embolden(&pFace->glyph->outline, __fontAttrib.boldWeight.__fixedPoint);
670 FT_Render_Glyph(pFace->glyph, FT_RENDER_MODE_NORMAL);
672 else if (__fontAttrib.quality == _IFont::QUALITY_MONO)
674 //TODO sunmi557.shin, will not support
675 FT_Error errCode = 1;
677 errCode = FT_Load_Glyph(pFace, glyphIndex, FT_LOAD_RENDER | FT_LOAD_MONOCHROME);
681 SysLogException(NID_GRP, E_SYSTEM, "[E_SYSTEM] FT_Load_Glyph_MONO(errCode = %#x)=", errCode);
688 SysLogException(NID_GRP, E_SYSTEM, "[E_SYSTEM] The quality of the FontFT2 is invalid!");
693 __isLoadGlyph = __ConvertPrivateToImage(pFace->glyph, ppFontGlyphData);
697 rtn = AddCache(glyphIndex, __fontAttrib.size, __fontAttrib.style, *ppFontGlyphData);
700 if (*ppFontGlyphData != null)
702 (*ppFontGlyphData)->hasOwnerShip = (__isLoadGlyph) ? 1 : 0;
705 return __isLoadGlyph;
709 _FontFt2::UnloadGlyph(Glyph** ppFontGlyphData)
716 CHECK_NULL_PARAM(ppFontGlyphData);
718 if ((*ppFontGlyphData) && ((*ppFontGlyphData)->hasOwnerShip == 0))
723 delete[] (char*) (*ppFontGlyphData);
725 *ppFontGlyphData = null;
726 __isLoadGlyph = false;
732 _FontFt2::CheckGlyph(unsigned long character)
734 return __GetGlyphIndex(character);
738 _FontFt2::GetFontSizeProperty(SizeProperty& sizeProperty) const
745 FT_Face pFace = (FT_Face) __pFontFace;
747 if (FT_IS_SCALABLE(pFace))
750 if (pFace->size == null)
757 sizeProperty.maxWidth.Reset(pFace->size->metrics.max_advance);
758 sizeProperty.maxHeight.Reset(pFace->size->metrics.height);
759 sizeProperty.baseLine.Reset(pFace->size->metrics.height + pFace->size->metrics.descender);
760 sizeProperty.ascender.Reset(pFace->size->metrics.ascender);
761 sizeProperty.descender.Reset(pFace->size->metrics.descender); // (-)
762 sizeProperty.leading.Reset(pFace->size->metrics.height - pFace->size->metrics.ascender + pFace->size->metrics.descender);
765 if (_CompareFamilyForTitling(pFace->family_name))
767 _Util::FixedPoint26_6 min;
768 _Util::FixedPoint26_6 max;
770 min.Reset((pFace->bbox.yMin * pFace->size->metrics.y_ppem) / pFace->units_per_EM);
771 max.Reset((pFace->bbox.yMax * pFace->size->metrics.y_ppem) / pFace->units_per_EM);
773 if (sizeProperty.ascender < max)
775 sizeProperty.ascender = max;
778 if (sizeProperty.descender > min)
780 sizeProperty.descender = min;
783 sizeProperty.maxHeight = sizeProperty.ascender - sizeProperty.descender;
784 sizeProperty.baseLine = sizeProperty.maxHeight + sizeProperty.descender;
785 sizeProperty.leading = sizeProperty.maxHeight - sizeProperty.ascender + sizeProperty.descender;
789 // min/max size need to be verified
791 sizeProperty.minSize = _Util::FixedPoint26_6(8);
792 sizeProperty.maxSize = _Util::FixedPoint26_6(540);
803 _FontFt2::__InitProperty()
810 FT_Face pFace = (FT_Face) __pFontFace;
812 if (FT_IS_SCALABLE(pFace))
815 if (pFace->size == null)
820 TT_OS2* pFontSpecTable = (TT_OS2*)FT_Get_Sfnt_Table(pFace, ft_sfnt_os2);
823 __fontProperty.pFamilyName = pFace->family_name;
824 __fontProperty.pStyleName = pFace->style_name;
825 __fontProperty.weightClass = (pFontSpecTable != null) ? pFontSpecTable->usWeightClass : 400;
826 __fontProperty.styleFlag = pFace->style_flags;
828 // engine name and min/max size need to be verified
829 __fontProperty.pEngineName = "FreeType2";
830 __fontProperty.styleCaps = _IFont::STYLE_ITALIC | _IFont::STYLE_BOLD | _IFont::STYLE_BACKSLANT;
831 __fontProperty.fontCaps = _IFont::CAPS_SCALABLE | _IFont::CAPS_ANGLE | _IFont::CAPS_X_EXPANSION | _IFont::CAPS_QUALITY_MONO |
832 _IFont::CAPS_QUALITY_LOW | _IFont::CAPS_QUALITY_MEDIUM | _IFont::CAPS_QUALITY_HIGH;
834 FT_Set_Char_Size(FT_Face(__pFontFace), __fontAttrib.size.__fixedPoint * _DEFAULT_RES, __fontAttrib.size.__fixedPoint * _DEFAULT_RES, 1, 1);
836 static const char* emojiFaceNames[] =
843 for (unsigned int i = 0; i < sizeof(emojiFaceNames) / sizeof(emojiFaceNames[0]); i++)
845 if (strcmp(__fontProperty.pFamilyName, emojiFaceNames[i]) == 0)
861 _FontFt2::IsEmoji(void) const
867 _FontFt2::GetFontProperty(Property& property) const
874 property.pFamilyName = __fontProperty.pFamilyName;
875 property.pStyleName = __fontProperty.pStyleName;
876 property.styleFlag = __fontProperty.styleFlag;
877 property.weightClass = __fontProperty.weightClass;
878 property.pEngineName = __fontProperty.pEngineName;
879 property.styleCaps = __fontProperty.styleCaps;
880 property.fontCaps = __fontProperty.fontCaps;
886 _FontFt2::GetFallbackMap()
888 return &__fallbackFontMap;
892 _FontFt2::GetGlyphList(const _Util::String& reorderedText, Tizen::Base::Collection::IListT<_IFont::Glyph *>& out, int script)
894 FT_Face pFace = FT_Face(__pFontFace);
898 FT_Vector pen = {0, 0};
900 __SetTransMatrix(&matrix);
902 FT_Set_Transform(pFace, &matrix, &pen);
905 _FontGlyphList glyphList(reorderedText, pFace, script);
911 bool isSynthetic = (__fontAttrib.style & _IFont::STYLE_BOLD) && (__fontProperty.weightClass < _MEDIUM_FONT_BOLD_WEIGHT);
913 for (unsigned int i = 0; i < glyphList.GetCount(); i++)
915 const _FontGlyphList::GlyphAuxInfo& auxInfo = glyphList.GetGlyphAuxInfo(i);
917 if (!auxInfo.isAvailable)
919 _IFont::Glyph* pFontGlyphData = (_IFont::Glyph*) new (std::nothrow) char[sizeof(_IFont::Glyph)];
923 memset(pFontGlyphData, 0, sizeof(_IFont::Glyph));
924 pFontGlyphData->hasOwnerShip = 1;
925 out.Add(pFontGlyphData);
931 FT_UInt glyphIndex = auxInfo.glyphIndex;
933 // bidi cache underdevelop
934 _IFont::Glyph* pFontGlyphData;
936 bool rtn = FindCache(glyphIndex, __fontAttrib.size, __fontAttrib.style, &pFontGlyphData);
940 int bufferSize = sizeof(_IFont::Glyph) + (pFontGlyphData->image.bytesPerLine * pFontGlyphData->image.height);
942 _IFont::Glyph* pTempGlyphData = (_IFont::Glyph*) new (std::nothrow) char[bufferSize];
946 memcpy(pTempGlyphData, pFontGlyphData, bufferSize);
948 _Util::FixedPoint22_10 xOffset;
949 _Util::FixedPoint22_10 yOffset;
950 _Util::FixedPoint22_10 xAdvance;
951 _Util::FixedPoint22_10 yAdvance;
952 xOffset.Reset(auxInfo.xOffset.__fixedPoint << 4);
953 yOffset.Reset(auxInfo.yOffset.__fixedPoint << 4);
954 xAdvance.Reset(auxInfo.xAdvance.__fixedPoint << 4);
955 yAdvance.Reset(-auxInfo.yAdvance.__fixedPoint << 4);
957 pTempGlyphData->xOffset = pTempGlyphData->xOffset + xOffset;
958 pTempGlyphData->yOffset = pTempGlyphData->yOffset + yOffset;
959 pTempGlyphData->xAdvance = xAdvance;
960 pTempGlyphData->yAdvance = yAdvance;
962 pTempGlyphData->image.pBitmap = (unsigned char*)(pTempGlyphData + 1);
963 pTempGlyphData->hasOwnerShip = 1;
965 out.Add(pTempGlyphData);
973 error = FT_Load_Glyph(pFace, glyphIndex, FT_LOAD_DEFAULT | FT_LOAD_NO_BITMAP);
977 error = FT_Load_Glyph(pFace, glyphIndex, /*FT_LOAD_RENDER*/FT_LOAD_DEFAULT/* | FT_LOAD_NO_BITMAP*/);
987 FT_Outline_Embolden(&pFace->glyph->outline, __fontAttrib.boldWeight.__fixedPoint);
990 error = FT_Render_Glyph(pFace->glyph, FT_RENDER_MODE_NORMAL);
997 _IFont::GlyphBitmap image;
999 FT_GlyphSlot pSlot = FT_GlyphSlot(pFace->glyph);
1001 switch (pSlot->bitmap.pixel_mode)
1003 case ft_pixel_mode_mono:
1006 case ft_pixel_mode_grays:
1013 image.width = pSlot->bitmap.width;
1014 image.height = pSlot->bitmap.rows;
1015 image.bytesPerLine = pSlot->bitmap.pitch;
1016 image.pBitmap = pSlot->bitmap.buffer;
1018 pFontGlyphData = (_IFont::Glyph*) new (std::nothrow) char[sizeof(_IFont::Glyph) + (image.bytesPerLine * image.height)];
1020 if (pFontGlyphData == null)
1025 _Util::FixedPoint22_10 xOffset;
1026 _Util::FixedPoint22_10 yOffset;
1027 _Util::FixedPoint22_10 xAdvance;
1028 _Util::FixedPoint22_10 yAdvance;
1029 xOffset.Reset(auxInfo.xOffset.__fixedPoint << 4);
1030 yOffset.Reset(auxInfo.yOffset.__fixedPoint << 4);
1031 xAdvance.Reset(auxInfo.xAdvance.__fixedPoint << 4);
1032 yAdvance.Reset(-auxInfo.yAdvance.__fixedPoint << 4);
1034 pFontGlyphData->id = 0;
1035 pFontGlyphData->xOffset = xOffset + _Util::FixedPoint22_10(pSlot->bitmap_left);
1036 pFontGlyphData->yOffset = yOffset + _Util::FixedPoint22_10(pSlot->bitmap_top);
1037 pFontGlyphData->xAdvance = xAdvance;
1038 pFontGlyphData->yAdvance = yAdvance;
1039 pFontGlyphData->hasOwnerShip = 0;
1040 pFontGlyphData->image = image;
1042 pFontGlyphData->image.pBitmap = (unsigned char*)(pFontGlyphData + 1);
1043 memcpy(pFontGlyphData->image.pBitmap, image.pBitmap, image.bytesPerLine * image.height);
1045 out.Add(pFontGlyphData);
1047 pFontGlyphData->xOffset = _Util::FixedPoint22_10(pSlot->bitmap_left);
1048 pFontGlyphData->yOffset = _Util::FixedPoint22_10(pSlot->bitmap_top);
1050 AddCache(glyphIndex, __fontAttrib.size, __fontAttrib.style, pFontGlyphData);
1052 pFontGlyphData->hasOwnerShip = 1;
1059 _FontFt2::__CleanUp()
1061 if (__pFontFace != null)
1063 FT_Done_Face(FT_Face(__pFontFace));
1067 if (__pFontEngine != null)
1069 FT_Done_FreeType(FT_Library(__pFontEngine));
1070 __pFontEngine = null;
1073 if ((__pFontBuffer != null) && !__isStaticBuffer)
1075 delete[] static_cast<byte*>(__pFontBuffer);
1078 __pFontBuffer = null;
1079 __isStaticBuffer = false;
1083 _FontFt2::__GetGlyphIndex(unsigned long character) const
1090 FT_Face pFace = FT_Face(__pFontFace);
1097 if (pFace->charmap != null)
1099 unsigned long glyphIndex = FT_Get_Char_Index(pFace, character);
1108 _FontFt2::__ConvertPrivateToImage(void* pData1, _IFont::Glyph** ppFontGlyphData)
1115 FT_GlyphSlot pSlot = FT_GlyphSlot(pData1);
1117 _IFont::GlyphBitmap image;
1119 switch (pSlot->bitmap.pixel_mode)
1121 case ft_pixel_mode_mono:
1124 case ft_pixel_mode_grays:
1131 image.width = pSlot->bitmap.width;
1132 image.height = pSlot->bitmap.rows;
1133 image.bytesPerLine = pSlot->bitmap.pitch;
1134 image.pBitmap = pSlot->bitmap.buffer;
1136 *ppFontGlyphData = (_IFont::Glyph*) new (std::nothrow) char[sizeof(_IFont::Glyph) + (image.bytesPerLine * image.height)];
1138 if (*ppFontGlyphData == null)
1143 _Util::FixedPoint22_10 xAdvance;
1144 _Util::FixedPoint22_10 yAdvance;
1145 xAdvance.Reset(pSlot->advance.x << 4);
1146 yAdvance.Reset(-(pSlot->advance.y << 4));
1148 (*ppFontGlyphData)->id = 0;
1149 (*ppFontGlyphData)->xOffset = _Util::FixedPoint22_10(pSlot->bitmap_left);
1150 (*ppFontGlyphData)->yOffset = _Util::FixedPoint22_10(pSlot->bitmap_top);
1151 (*ppFontGlyphData)->xAdvance = xAdvance;
1152 (*ppFontGlyphData)->yAdvance = yAdvance;
1153 (*ppFontGlyphData)->hasOwnerShip = 0;
1154 (*ppFontGlyphData)->image = image;
1156 // shkim, set the memory address of bitmap to the allocated by ourself above
1157 //(*pFontGlyphData)->image.bitmap = (unsigned char*)((*pFontGlyphData) + 1);
1159 if (image.width == 0 || image.height == 0)
1164 //memcpy((*ppFontGlyphData)->image.bitmap, image.bitmap, image.bytesPerLine * image.height);
1170 _FontFt2::__SetTransMatrix(void* pMatrix)
1177 if (pMatrix == null)
1182 FT_Matrix* pTrans = (FT_Matrix*) pMatrix;
1184 double radian = _M_PI / 180.0;
1186 if (_IsEqual(0.0f, __fontAttrib.angle))
1189 pTrans->xx = (FT_Fixed) (0x10000 * (__fontAttrib.xExpansion)) / 100;
1190 pTrans->xy = (FT_Fixed) 0;
1191 pTrans->yx = (FT_Fixed) 0;
1192 pTrans->yy = (FT_Fixed) 0x10000;
1194 // apply italic style
1195 if (__fontAttrib.style & _IFont::STYLE_ITALIC)
1197 pTrans->xy = (FT_Fixed) (sin(_ITALIC_ANGLE * radian) * 0x10000);
1199 else if (__fontAttrib.style & _IFont::STYLE_BACKSLANT)
1201 pTrans->xy = (FT_Fixed) (sin(-_ITALIC_ANGLE * radian) * 0x10000);
1206 double radAngle = __fontAttrib.angle * radian;
1208 pTrans->xx = (FT_Fixed) (cos(radAngle) * (__fontAttrib.xExpansion) * 0x10000) / 100;
1209 pTrans->xy = (FT_Fixed) (-sin(radAngle) * 0x10000);
1210 pTrans->yx = (FT_Fixed) (sin(radAngle) * (__fontAttrib.xExpansion) * 0x10000) / 100;
1211 pTrans->yy = (FT_Fixed) (cos(radAngle) * 0x10000);
1213 // apply italic style
1214 if (__fontAttrib.style & _IFont::STYLE_ITALIC)
1216 pTrans->xy = (FT_Fixed) ((cos(radAngle) * tan(_ITALIC_ANGLE * radian) - sin(radAngle)) * 0x10000);
1217 pTrans->yy = (FT_Fixed) ((sin(radAngle) * tan(_ITALIC_ANGLE * radian) + cos(radAngle)) * 0x10000);
1219 else if (__fontAttrib.style & _IFont::STYLE_BACKSLANT)
1221 pTrans->xy = (FT_Fixed) ((cos(radAngle) * tan(-_ITALIC_ANGLE * radian) - sin(radAngle)) * 0x10000);
1222 pTrans->yy = (FT_Fixed) ((sin(radAngle) * tan(-_ITALIC_ANGLE * radian) + cos(radAngle)) * 0x10000);
1229 }} // Tizen::Graphics