2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 FT_FREETYPE_H
33 #include <FBaseErrors.h>
35 #include <FBaseSysLog.h>
36 #include <FBaseUtilStringUtil.h>
37 #include <FBaseColIHashCodeProviderT.h>
39 #include "FGrp_FontFt2.h"
40 #include "FGrp_FontCache.h"
41 #include "util/FGrp_UtilTemplate.h"
47 #define CHECK_NULL_PARAM(data) if (data == null) \
51 #define CONVERT_INTEGER_TO_26_6_FIXED_POINT(value) (value * 64)
52 #define CONVERT_26_6_FIXED_POINT_TO_INTEGER(value) (value / 64)
54 using namespace Tizen::Base;
55 using namespace Tizen::Base::Collection;
59 const double _M_PI = 3.14159265358979323846;
60 const double _ITALIC_ANGLE = 10.619655;
61 const long _DEFAULT_FONT_SIZE = CONVERT_INTEGER_TO_26_6_FIXED_POINT(16); // 16 pixel size in 26.6 fixed point
62 const long _DEFAULT_RES = 72;
63 const long _FIXED_SHIFT = 10; // in fixed point number, the number of assigned bit below point.
64 const unsigned long _INDEX_FIRST = 32; // in first resource, the first chracter(space)
65 const unsigned long _INDEX_COUNT = 95; // first resource character count
68 _CompareFamilyForTitling(String& familyName)
72 L"TitlingGothicFB Comp",
73 L"TitlingGothicFB Cond",
74 L"TitlingGothicFB Narrow",
75 L"TitlingGothicFB Skyline"
78 for (unsigned int i = 0; i < sizeof(_compNames) / sizeof(_compNames[0]); i++)
80 if (familyName == _compNames[i])
89 const hb_script_t _HarfbuzzScript[] =
101 HB_SCRIPT_DEVANAGARI,
121 HB_SCRIPT_OLD_ITALIC,
131 HB_SCRIPT_CANADIAN_ABORIGINAL,
138 /* Unicode-4.0 additions */
148 /* Unicode-4.1 additions */
149 HB_SCRIPT_NEW_TAI_LUE,
151 HB_SCRIPT_GLAGOLITIC,
153 HB_SCRIPT_SYLOTI_NAGRI,
154 HB_SCRIPT_OLD_PERSIAN,
155 HB_SCRIPT_KHAROSHTHI,
157 /* Unicode-5.0 additions */
161 HB_SCRIPT_PHOENICIAN,
165 /* Unicode-5.1 additions */
170 HB_SCRIPT_SAURASHTRA,
178 /* Unicode-5.2 additions */
181 HB_SCRIPT_EGYPTIAN_HIEROGLYPHS,
182 HB_SCRIPT_IMPERIAL_ARAMAIC,
183 HB_SCRIPT_INSCRIPTIONAL_PAHLAVI,
184 HB_SCRIPT_INSCRIPTIONAL_PARTHIAN,
189 HB_SCRIPT_MEETEI_MAYEK,
190 HB_SCRIPT_OLD_SOUTH_ARABIAN,
191 HB_SCRIPT_OLD_TURKIC,
195 /* Unicode-6.0 additions */
202 class _FontHashCodeProvider
203 : public IHashCodeProviderT <T>
206 _FontHashCodeProvider(void)
210 virtual ~_FontHashCodeProvider(void)
214 virtual int GetHashCode(const T& obj) const
216 return obj.GetHashCode();
222 : public IComparerT <T>
229 virtual ~_FontComparer(void)
233 virtual result Compare(const T& obj1, const T& obj2, int& cmp) const
235 String& objString1 = static_cast <String&>(const_cast <T&>(obj1));
236 String& objString2 = static_cast <String&>(const_cast <T&>(obj2));
238 cmp = objString1.CompareTo(objString2);
244 const _FontHashCodeProvider<String> _fontHashCodeProvider;
245 const _FontComparer<String> _fontComparer;
249 namespace Tizen { namespace Graphics
253 _IsEqual(float f1, float f2)
255 return (((f1 > f2) ? f1 - f2 : f2 - f1) < 0.00001f); // epsilon is assumed to be 0.0001, not 1.192092896e-07f
260 , __isLoadGlyph(false)
261 , __pFontEngine(null)
263 , __pFontBuffer(null)
264 , __isStaticBuffer(false)
266 __fontAttrib.size = _DEFAULT_FONT_SIZE;
267 __fontAttrib.angle = 0.0f;
268 __fontAttrib.style = _IFont::STYLE_NONE;
269 __fontAttrib.quality = _IFont::QUALITY_HIGH;
270 __fontAttrib.xExpansion = 100;
271 __fontAttrib.boldWeight = 1 << 6; //5L<<14;
273 __fallbackFontMap.Construct(1, 0, _fontHashCodeProvider, _fontComparer);
276 __fontCache.reset(new (std::nothrow) _FontCache());
279 _FontFt2::~_FontFt2()
289 __fallbackFontMap.RemoveAll();
293 _FontFt2::Create(const void* pBuffer, long bufSize, long face)
300 int error = FT_Init_FreeType(static_cast<FT_Library*>((void*) &__pFontEngine));
309 // should keep the buffer
310 __pFontBuffer = new (std::nothrow) byte[bufSize];
319 memcpy(__pFontBuffer, pBuffer, bufSize);
321 error = FT_New_Memory_Face(FT_Library(__pFontEngine), (const byte*) __pFontBuffer, bufSize, face, static_cast<FT_Face*>((void*) &__pFontFace));
330 FT_Face pFace = FT_Face(__pFontFace);
332 if ((pFace->charmap == null) && (pFace->num_charmaps > 0))
334 FT_Set_Charmap(pFace, pFace->charmaps[0]);
343 _FontFt2::Create(const char* pFilePath, long face)
350 int error = FT_Init_FreeType(static_cast<FT_Library*>((void*) &__pFontEngine));
359 error = FT_New_Face(FT_Library(__pFontEngine), pFilePath, face, static_cast<FT_Face*>((void*) &__pFontFace));
368 FT_Face pFace = FT_Face(__pFontFace);
370 if ((pFace->charmap == null) && (pFace->num_charmaps > 0))
372 FT_Set_Charmap(pFace, pFace->charmaps[0]);
381 _FontFt2::CreateStatic(const void* pBuffer, long bufSize, long face)
388 FT_Face pFace = null;
390 int error = FT_Init_FreeType(static_cast<FT_Library*>((void*) &__pFontEngine));
399 __pFontBuffer = const_cast<void*>(pBuffer);
400 __isStaticBuffer = true;
402 error = FT_New_Memory_Face(FT_Library(__pFontEngine), (const byte*) __pFontBuffer, bufSize, face, static_cast<FT_Face*>((void*) &__pFontFace));
411 pFace = FT_Face(__pFontFace);
413 if ((pFace->charmap == null) && (pFace->num_charmaps > 0))
415 FT_Set_Charmap(pFace, pFace->charmaps[0]);
423 _FontFt2::Reload(const void* pBuffer, long bufSize, long face)
430 std::unique_ptr<byte[]> pReloadBuffer(new (std::nothrow) byte[bufSize]);
432 if (pReloadBuffer == null)
437 memcpy(pReloadBuffer.get(), pBuffer, bufSize);
439 void* pReloadFace = null;
441 int error = FT_New_Memory_Face(FT_Library(__pFontEngine), (const byte*) pReloadBuffer.get(), bufSize, face, static_cast<FT_Face*>((void*) &pReloadFace));
451 FT_Done_Face(FT_Face(__pFontFace));
455 if (__pFontBuffer && !__isStaticBuffer)
457 delete[] static_cast<byte*>(__pFontBuffer);
460 // assign new resource
461 __pFontBuffer = pReloadBuffer.release();
462 __pFontFace = pReloadFace;
463 __isStaticBuffer = false;
465 FT_Face pFace = FT_Face(__pFontFace);
467 if ((pFace->charmap == null) && (pFace->num_charmaps > 0))
469 FT_Set_Charmap(pFace, pFace->charmaps[0]);
478 _FontFt2::Reload(const char* filePath, long face)
485 void* pReloadFace = null;
487 int error = FT_New_Face(FT_Library(__pFontEngine), filePath, face, static_cast<FT_Face*>((void*) &pReloadFace));
497 FT_Done_Face(FT_Face(__pFontFace));
501 // assign new resource
502 __pFontFace = pReloadFace;
503 __isStaticBuffer = false;
505 FT_Face pFace = FT_Face(__pFontFace);
507 if ((pFace->charmap == null) && (pFace->num_charmaps > 0))
509 FT_Set_Charmap(pFace, pFace->charmaps[0]);
518 _FontFt2::Destroy(void)
530 _FontFt2::FindCache(unsigned long character, int size, int style, Glyph** pOut)
532 return (__fontCache.get()) ? __fontCache->Find(character, __fontAttrib.size, __fontAttrib.style, pOut) : false;
536 _FontFt2::AddCache(unsigned long character, int size, int style, Glyph* pGlyph)
538 return (__fontCache.get()) ? __fontCache->Add(character, size, style, pGlyph) : false;
542 _FontFt2::CleanCache()
544 return (__fontCache.get()) ? __fontCache->Cleanup() : false;
548 _FontFt2::SetAttrib(const Attrib& fontAttrib)
555 if (!(fontAttrib.size >= CONVERT_INTEGER_TO_26_6_FIXED_POINT(1)) ||
556 !(fontAttrib.quality >= 0 && fontAttrib.quality <= 3) ||
557 !(fontAttrib.xExpansion >= 1) ||
558 !(CONVERT_26_6_FIXED_POINT_TO_INTEGER(fontAttrib.size) * fontAttrib.xExpansion >= _DEFAULT_RES) ||
559 !(fontAttrib.boldWeight > 0))
564 if (FT_IS_SCALABLE(FT_Face(__pFontFace)) == 0)
569 if (FT_Set_Char_Size(FT_Face(__pFontFace), fontAttrib.size * _DEFAULT_RES, fontAttrib.size * _DEFAULT_RES, 1, 1) > 0)
575 memcpy(&__fontAttrib, &fontAttrib, sizeof(fontAttrib));
581 _FontFt2::GetAttrib(Attrib& fontAttrib) const
588 fontAttrib.angle = __fontAttrib.angle;
589 fontAttrib.quality = __fontAttrib.quality;
590 fontAttrib.size = __fontAttrib.size;
591 fontAttrib.style = __fontAttrib.style;
592 fontAttrib.xExpansion = __fontAttrib.xExpansion;
593 fontAttrib.boldWeight = __fontAttrib.boldWeight;
599 _FontFt2::GetKerning(unsigned long character1, unsigned long character2, long& xVector, long& yVector) const
606 bool isCharacter1InEnglish = false;
607 bool isCharacter2InEnglish = false;
608 FT_Face pFace = null;
609 unsigned long index1 = 0;
610 unsigned long index2 = 0;
612 if (character1 >= _INDEX_FIRST && character1 < (_INDEX_FIRST + _INDEX_COUNT))
614 isCharacter1InEnglish = true;
617 if (character2 >= _INDEX_FIRST && character2 < (_INDEX_FIRST + _INDEX_COUNT))
619 isCharacter2InEnglish = true;
622 if (isCharacter1InEnglish != isCharacter2InEnglish)
629 pFace = FT_Face(__pFontFace);
630 index1 = __GetCharIndex(character1);
631 index2 = __GetCharIndex(character2);
633 bool hasKerning = false;
635 hasKerning = (FT_HAS_KERNING(pFace) != 0);
641 int isSuccess = FT_Get_Kerning(pFace, index1, index2, ft_kerning_default, &delta);
643 if (isSuccess != 0) //0 means success.
648 const int shiftBit = 6;
649 xVector = (delta.x >> shiftBit);
650 yVector = (delta.y >> shiftBit);
662 _FontFt2::LoadGlyph(unsigned long character, Glyph** ppFontGlyphData)
669 CHECK_NULL_PARAM(__pFontFace);
670 CHECK_NULL_PARAM(ppFontGlyphData);
673 rtn = FindCache(character, __fontAttrib.size, __fontAttrib.style, ppFontGlyphData);
679 *ppFontGlyphData = null;
681 FT_Face pFace = null;
682 FT_UInt ixCurr = character;
684 pFace = FT_Face(__pFontFace);
687 if (!FT_IS_SCALABLE(pFace))
689 SysLog(NID_GRP, "[] FT_IS_SCALABLE has been failed");
692 // retrieve glyph index from character code
693 ixCurr = __GetCharIndex(character);
695 // set transformation
697 FT_Vector pen = {0, 0};
698 __SetTransMatrix(&matrix);
699 FT_Set_Transform(pFace, &matrix, &pen);
701 if (__fontAttrib.quality == _IFont::QUALITY_MONO)
703 //TODO sunmi557.shin, will not support
704 FT_Error errCode = 1;
706 errCode = FT_Load_Glyph(pFace, ixCurr, FT_LOAD_RENDER | FT_LOAD_MONOCHROME);
710 SysLogException(NID_GRP, E_SYSTEM, "[E_SYSTEM] FT_Load_Glyph_MONO(errCode = %#x)=", errCode);
715 else if (__fontAttrib.quality == _IFont::QUALITY_LOW ||
716 __fontAttrib.quality == _IFont::QUALITY_MEDIUM ||
717 __fontAttrib.quality == _IFont::QUALITY_HIGH)
719 FT_Error errCode = 1;
721 bool isSynthetic = (__fontAttrib.style & _IFont::STYLE_BOLD) && !(pFace->style_flags & FT_STYLE_FLAG_BOLD);
725 errCode = FT_Load_Glyph(pFace, ixCurr, FT_LOAD_DEFAULT | FT_LOAD_NO_BITMAP);
729 //errCode = FT_Load_Glyph(pFace, ixCurr, FT_LOAD_RENDER);
730 errCode = FT_Load_Glyph(pFace, ixCurr, FT_LOAD_DEFAULT);
733 if (errCode) // 0: success
735 SysLogException(NID_GRP, E_SYSTEM, "[E_SYSTEM] FT_Load_Glyph_HighQuality(errCode = %#x)=", errCode);
742 FT_Outline_Embolden(&pFace->glyph->outline, __fontAttrib.boldWeight);
745 FT_Render_Glyph(pFace->glyph, FT_RENDER_MODE_NORMAL);
750 SysLogException(NID_GRP, E_SYSTEM, "[E_SYSTEM] The quality of the FontFT2 is invalid!");
755 __isLoadGlyph = __ConvertPrivateToImage(pFace->glyph, ppFontGlyphData);
759 rtn = AddCache(character, __fontAttrib.size, __fontAttrib.style, *ppFontGlyphData);
762 if (*ppFontGlyphData != null)
764 (*ppFontGlyphData)->hasOwnerShip = (__isLoadGlyph) ? 1 : 0;
767 return __isLoadGlyph;
771 _FontFt2::UnloadGlyph(Glyph** ppFontGlyphData)
778 CHECK_NULL_PARAM(ppFontGlyphData);
780 if ((*ppFontGlyphData) && ((*ppFontGlyphData)->hasOwnerShip == 0))
785 delete[] (char*) (*ppFontGlyphData);
787 *ppFontGlyphData = null;
788 __isLoadGlyph = false;
794 _FontFt2::CheckGlyph(unsigned long character)
796 return __GetCharIndex(character);
800 _FontFt2::GetFontProperty(Property& property) const
807 FT_Face face = (FT_Face) __pFontFace;
809 if (FT_IS_SCALABLE(face))
811 const int shiftBit = 6;
814 if (face->size == null)
820 property.pFamilyName = face->family_name;
821 property.pStyleName = face->style_name;
822 property.maxWidth = face->size->metrics.max_advance >> shiftBit;
823 property.maxHeight = face->size->metrics.height >> shiftBit;
824 property.baseLine = (face->size->metrics.height + face->size->metrics.descender) >> shiftBit;
825 property.ascender = face->size->metrics.ascender >> shiftBit;
826 property.descender = face->size->metrics.descender >> shiftBit; // (-)
827 property.leading = (face->size->metrics.height - face->size->metrics.ascender + face->size->metrics.descender) >> shiftBit;
829 String familyName = String(property.pFamilyName);
831 if (_CompareFamilyForTitling(familyName))// temp
833 int min = (face->bbox.yMin * face->size->metrics.y_ppem) / face->units_per_EM;
834 int max = (face->bbox.yMax * face->size->metrics.y_ppem) / face->units_per_EM;
836 if (property.ascender < max)
838 property.ascender = max;
841 if (property.descender > min)
843 property.descender = min;
846 property.maxHeight = property.ascender - property.descender;
847 property.baseLine = (property.maxHeight + property.descender) >> shiftBit;
848 property.leading = (property.maxHeight - property.ascender + property.descender) >> shiftBit;
852 // engine name and min/max size need to be verified
853 property.pEngineName = "FreeType2";
854 property.minSize = 8;
855 property.maxSize = 540;
856 property.styleCaps = _IFont::STYLE_ITALIC | _IFont::STYLE_BOLD | _IFont::STYLE_BACKSLANT;
857 property.fontCaps = _IFont::CAPS_SCALABLE | _IFont::CAPS_ANGLE | _IFont::CAPS_X_EXPANSION | _IFont::CAPS_QUALITY_MONO |
858 _IFont::CAPS_QUALITY_LOW | _IFont::CAPS_QUALITY_MEDIUM | _IFont::CAPS_QUALITY_HIGH;
868 Tizen::Base::Collection::HashMapT<Tizen::Base::String, _IFont::SharedFontResource>*
869 _FontFt2::GetFallbackMap()
871 return &__fallbackFontMap;
875 _FontFt2::GetGlyphList(const _Util::String& text, Tizen::Base::Collection::IListT<_IFont::Glyph *>& out, bool isRtl, int script) const
877 //hb_font_funcs_t *ffuncs;
879 hb_buffer_t *hBuffer = null;
880 hb_glyph_position_t *positions = null;
881 hb_glyph_info_t *infos = null;
884 /*FriBidiChar *friText = new (std::nothrow) FriBidiChar[length];
885 FriBidiCharType *ctypes = new (std::nothrow) FriBidiCharType[length];
886 FriBidiLevel *emblevels = new (std::nothrow) FriBidiLevel[length];
887 FriBidiJoiningType *join_types = new (std::nothrow) FriBidiJoiningType[length];
888 FriBidiParType base_direction = FRIBIDI_PAR_ON;
889 FriBidiCharType type;
890 char *ouputChar = new (std::nothrow) char[length];*/
892 //int last_break = 0;
896 ffuncs = hb_font_funcs_create ();
897 hb_font_funcs_set_glyph_h_advance_func (ffuncs, glyph_h_advance_func, NULL, NULL);
898 hb_font_funcs_set_glyph_func (ffuncs, glyph_func, NULL, NULL);
899 hb_font_funcs_set_glyph_h_kerning_func (ffuncs, glyph_h_kerning_func, NULL, NULL);
900 hb_font_set_funcs (hFont, ffuncs, NULL, NULL);*/
902 // if(hb_version_check(0, 9, 0))//0.9.0
904 // hBuffer = hb_buffer_create();
905 // hb_buffer_set_unicode_funcs(hBuffer, hb_unicode_funcs_get_default());
906 // hb_buffer_set_language(hBuffer, hb_language_from_string("th", -1));
910 face = FT_Face(__pFontFace);
912 hb_font_t *hFont = hb_ft_font_create (face, NULL);
913 hb_font_t *hSubFont = hb_font_create_sub_font(hFont);
914 hb_font_destroy (hFont);
916 hBuffer = hb_buffer_create();
917 hb_buffer_set_unicode_funcs(hBuffer, hb_unicode_funcs_get_default());
918 //hb_buffer_set_language(hBuffer, hb_language_from_string("th"));
922 //hb_buffer_set_language(hBuffer, hb_language_from_string("ar", -1));
923 hb_buffer_set_script(hBuffer, _HarfbuzzScript[script]);
924 hb_buffer_set_direction(hBuffer, HB_DIRECTION_RTL);
928 //hb_buffer_set_language(hBuffer, hb_language_from_string("en", -1));
929 //hb_buffer_set_script(hBuffer, HB_SCRIPT_THAI);
930 //hb_buffer_set_direction(hBuffer, HB_DIRECTION_LTR);
931 hb_buffer_set_script(hBuffer, _HarfbuzzScript[script]);
932 hb_buffer_set_direction(hBuffer, HB_DIRECTION_LTR);
935 if (sizeof(wchar_t) == sizeof(uint32_t))
937 hb_buffer_add_utf32(hBuffer, (const uint32_t*)text.pStart, text.length, 0, text.length);
941 uint32_t* pDst = new (std::nothrow) uint32_t[text.length + 1];
946 const wchar_t* pSrc = text.pStart;
948 uint32_t* pDstBegin = pDst;
949 uint32_t* pDstEnd = pDstBegin + text.length;
951 while (pDstBegin < pDstEnd)
953 *pDstBegin++ = *pSrc++;
959 hb_buffer_add_utf32(hBuffer, pDst, text.length, 0, text.length);
966 hb_font_funcs_t *font_funcs = hb_font_funcs_create();
968 hb_font_funcs_set_glyph_h_advance_func(font_funcs, _evas_common_font_ot_hb_get_glyph_advance, NULL, NULL);
969 hb_font_funcs_set_glyph_h_kerning_func(font_funcs, _evas_common_font_ot_hb_get_kerning, NULL, NULL);
971 hb_font_set_funcs(hSubFont, font_funcs, fi, NULL);
974 hb_shape (hSubFont, hBuffer, NULL, 0);
976 slen = hb_buffer_get_length (hBuffer);
977 positions = hb_buffer_get_glyph_positions (hBuffer, NULL);
978 infos = hb_buffer_get_glyph_infos (hBuffer, NULL);
980 //_IFont::Glyph *pFontGlyphData = (_IFont::Glyph*) new (std::nothrow) char[sizeof(_IFont::Glyph) + (image.bytesPerLine * image.height)];
984 for(unsigned int i = 0; i < slen; i++)
986 FT_UInt glyph_index = infos->codepoint;
988 _IFont::GlyphBitmap image;
990 FT_Error error = FT_Load_Glyph(face, glyph_index, /*FT_LOAD_RENDER*/FT_LOAD_DEFAULT/* | FT_LOAD_NO_BITMAP*/);
996 error = FT_Render_Glyph(face->glyph, FT_RENDER_MODE_NORMAL);
1002 FT_GlyphSlot pSlot = FT_GlyphSlot(face->glyph);
1004 switch (pSlot->bitmap.pixel_mode)
1006 case ft_pixel_mode_mono:
1010 case ft_pixel_mode_grays:
1018 image.width = pSlot->bitmap.width;
1019 image.height = pSlot->bitmap.rows;
1020 image.bytesPerLine = pSlot->bitmap.pitch;
1021 image.pBitmap = pSlot->bitmap.buffer;
1023 _IFont::Glyph *pFontGlyphData = (_IFont::Glyph*) new (std::nothrow) char[sizeof(_IFont::Glyph) + (image.bytesPerLine * image.height)];
1025 if (pFontGlyphData == null)
1028 pFontGlyphData->id = 0;
1029 pFontGlyphData->xOffset = (positions->x_offset >> 6) + pSlot->bitmap_left;
1030 pFontGlyphData->yOffset = (positions->y_offset >> 6) + pSlot->bitmap_top;
1031 pFontGlyphData->xAdvance = pSlot->advance.x << (_FIXED_SHIFT - 6);
1032 pFontGlyphData->yAdvance = -(pSlot->advance.y << (_FIXED_SHIFT - 6));
1033 //pFontGlyphData->xOffset = positions->x_offset;
1034 //pFontGlyphData->yOffset = positions->y_offset;
1035 //pFontGlyphData->xAdvance = positions->x_advance;
1036 //pFontGlyphData->yAdvance = positions->y_advance;
1037 pFontGlyphData->image = image;
1039 pFontGlyphData->image.pBitmap = (unsigned char*)(pFontGlyphData + 1);
1040 memcpy(pFontGlyphData->image.pBitmap, image.pBitmap, image.bytesPerLine * image.height);
1042 out.Add(pFontGlyphData);
1048 hb_font_destroy (hSubFont);
1049 hb_buffer_destroy(hBuffer);
1055 _FontFt2::__CleanUp()
1059 FT_Done_Face(FT_Face(__pFontFace));
1065 FT_Done_FreeType(FT_Library(__pFontEngine));
1066 __pFontEngine = null;
1069 if (__pFontBuffer && !__isStaticBuffer)
1071 delete[] static_cast<byte*>(__pFontBuffer);
1074 __pFontBuffer = null;
1075 __isStaticBuffer = false;
1079 _FontFt2::__GetCharIndex(unsigned long character) const
1086 FT_Face pFace = FT_Face(__pFontFace);
1094 unsigned long ixCurr = FT_Get_Char_Index(pFace, character);
1103 _FontFt2::__ConvertPrivateToImage(void* pData1, _IFont::Glyph** ppFontGlyphData)
1110 FT_GlyphSlot pSlot = FT_GlyphSlot(pData1);
1112 _IFont::GlyphBitmap image;
1114 switch (pSlot->bitmap.pixel_mode)
1116 case ft_pixel_mode_mono:
1119 case ft_pixel_mode_grays:
1126 image.width = pSlot->bitmap.width;
1127 image.height = pSlot->bitmap.rows;
1128 image.bytesPerLine = pSlot->bitmap.pitch;
1129 image.pBitmap = pSlot->bitmap.buffer;
1131 *ppFontGlyphData = (_IFont::Glyph*) new (std::nothrow) char[sizeof(_IFont::Glyph) + (image.bytesPerLine * image.height)];
1133 if (*ppFontGlyphData == null)
1138 (*ppFontGlyphData)->id = 0;
1139 (*ppFontGlyphData)->xOffset = pSlot->bitmap_left << _FIXED_SHIFT;
1140 (*ppFontGlyphData)->yOffset = pSlot->bitmap_top << _FIXED_SHIFT;
1141 (*ppFontGlyphData)->xAdvance = pSlot->advance.x << (_FIXED_SHIFT - 6);
1142 (*ppFontGlyphData)->yAdvance = -(pSlot->advance.y << (_FIXED_SHIFT - 6));
1143 (*ppFontGlyphData)->hasOwnerShip = 0;
1144 (*ppFontGlyphData)->image = image;
1146 // shkim, set the memory address of bitmap to the allocated by ourself above
1147 //(*pFontGlyphData)->image.bitmap = (unsigned char*)((*pFontGlyphData) + 1);
1149 if (image.width == 0 || image.height == 0)
1154 //memcpy((*ppFontGlyphData)->image.bitmap, image.bitmap, image.bytesPerLine * image.height);
1160 _FontFt2::__SetTransMatrix(void* pMatrix)
1167 if (pMatrix == null)
1172 FT_Matrix* pTrans = (FT_Matrix*) pMatrix;
1174 double radian = _M_PI / 180.0;
1176 if (_IsEqual(0.0f, __fontAttrib.angle))
1179 pTrans->xx = (FT_Fixed) (0x10000 * (__fontAttrib.xExpansion)) / 100;
1180 pTrans->xy = (FT_Fixed) 0;
1181 pTrans->yx = (FT_Fixed) 0;
1182 pTrans->yy = (FT_Fixed) 0x10000;
1184 // apply italic style
1185 if (__fontAttrib.style & _IFont::STYLE_ITALIC)
1187 pTrans->xy = (FT_Fixed) (sin(_ITALIC_ANGLE * radian) * 0x10000);
1189 else if (__fontAttrib.style & _IFont::STYLE_BACKSLANT)
1191 pTrans->xy = (FT_Fixed) (sin(-_ITALIC_ANGLE * radian) * 0x10000);
1196 double radAngle = __fontAttrib.angle * radian;
1198 pTrans->xx = (FT_Fixed) (cos(radAngle) * (__fontAttrib.xExpansion) * 0x10000) / 100;
1199 pTrans->xy = (FT_Fixed) (-sin(radAngle) * 0x10000);
1200 pTrans->yx = (FT_Fixed) (sin(radAngle) * (__fontAttrib.xExpansion) * 0x10000) / 100;
1201 pTrans->yy = (FT_Fixed) (cos(radAngle) * 0x10000);
1203 // apply italic style
1204 if (__fontAttrib.style & _IFont::STYLE_ITALIC)
1206 pTrans->xy = (FT_Fixed) ((cos(radAngle) * tan(_ITALIC_ANGLE * radian) - sin(radAngle)) * 0x10000);
1207 pTrans->yy = (FT_Fixed) ((sin(radAngle) * tan(_ITALIC_ANGLE * radian) + cos(radAngle)) * 0x10000);
1209 else if (__fontAttrib.style & _IFont::STYLE_BACKSLANT)
1211 pTrans->xy = (FT_Fixed) ((cos(radAngle) * tan(-_ITALIC_ANGLE * radian) - sin(radAngle)) * 0x10000);
1212 pTrans->yy = (FT_Fixed) ((sin(radAngle) * tan(-_ITALIC_ANGLE * radian) + cos(radAngle)) * 0x10000);
1219 }} // Tizen::Graphics