Add CreateFontN(FontMaxHeight)
authorSungyeon Woo <s.woo@samsung.com>
Wed, 7 Aug 2013 02:33:47 +0000 (11:33 +0900)
committerSungyeon Woo <s.woo@samsung.com>
Fri, 9 Aug 2013 09:06:12 +0000 (18:06 +0900)
Change-Id: Ib2b749a9083009732757ab0ca3a4ea7eee25a413
Signed-off-by: Sungyeon Woo <s.woo@samsung.com>
src/graphics/FGrp_Font.cpp
src/graphics/FGrp_Font.h
src/graphics/FGrp_FontFt2.cpp
src/graphics/FGrp_FontFt2.h
src/graphics/FGrp_FontImpl.cpp [changed mode: 0755->0644]
src/graphics/FGrp_FontRsrcManager.cpp
src/graphics/FGrp_IFont.h
src/graphics/FGrp_ResUtil.h
src/graphics/inc/FGrp_FontImpl.h [changed mode: 0755->0644]

index 16f3ca3..49315bb 100644 (file)
@@ -2228,6 +2228,40 @@ _Font::CheckGlyph(unsigned long character)
        return __pNativeFont->CheckGlyph(character);
 }
 
+float
+_Font::GetFontSizeFromMaxHeight(const _Util::FixedPoint26_6 expectedMaxHeight)
+{
+       return __pNativeFont->GetFontSizeFromMaxHeight(expectedMaxHeight);
+}
+
+float
+_Font::GetFontSizeFromMaxHeight(int style, const _Util::FixedPoint26_6 expectedMaxHeight)
+{
+       _FontRsrcManager& mgr = _FontRsrcManager::GetInstance();
+       _FontRsrcManager::SharedFontResource out;
+
+       result r = mgr.GetFont(style, expectedMaxHeight, out);
+       SysTryReturn(NID_GRP, r == E_SUCCESS, -1.0f, r, "[%s] Getting system default font failed.", GetErrorMessage(r));
+
+       _IFont* pTempFont = out.get();
+
+       return pTempFont->GetFontSizeFromMaxHeight(expectedMaxHeight);
+}
+
+float
+_Font::GetFontSizeFromMaxHeight(const Tizen::Base::String& fontName, int style, const _Util::FixedPoint26_6 expectedMaxHeight)
+{
+       _FontRsrcManager& mgr = _FontRsrcManager::GetInstance();
+       _FontRsrcManager::SharedFontResource out;
+
+       result r = mgr.GetFont(fontName, style, expectedMaxHeight, out);
+       SysTryReturn(NID_GRP, r == E_SUCCESS, -1.0f, r, "[%s] Getting font failed.", GetErrorMessage(r));
+
+       _IFont* pTempFont = out.get();
+
+       return pTempFont->GetFontSizeFromMaxHeight(expectedMaxHeight);
+}
+
 void
 _Font::__UpdateFontAttribute(int style, _Util::FixedPoint26_6 pcSize)
 {
index 2697f51..bdbf2da 100644 (file)
@@ -159,6 +159,11 @@ public:
        bool UnloadGlyph(_IFont::Glyph** ppFontGlyphData);
        unsigned long CheckGlyph(unsigned long character);
 
+       float GetFontSizeFromMaxHeight(const _Util::FixedPoint26_6 expectedMaxHeight);
+
+       static float GetFontSizeFromMaxHeight(int style, const _Util::FixedPoint26_6 expectedMaxHeight);
+       static float GetFontSizeFromMaxHeight(const Tizen::Base::String& fontName, int style, const _Util::FixedPoint26_6 expectedMaxHeight);
+
        static result DrawText(_Canvas& canvas, const Point& point, const Tizen::Base::String& text, int startIndex, int length);
        static result DrawText(_Canvas& canvas, const Point& point, const Tizen::Base::String& text, int startIndex, int length, const Color& outlineColor);
 
index 6ca3c5f..179a286 100644 (file)
@@ -1056,6 +1056,24 @@ _FontFt2::GetGlyphList(const _Util::String& reorderedText, Tizen::Base::Collecti
        return true;
 }
 
+float
+_FontFt2::GetFontSizeFromMaxHeight(_Util::FixedPoint26_6 expectedMaxHeight) const
+{
+       FT_Face pFace = (FT_Face) __pFontFace;
+
+       if (pFace == null)
+       {
+               return -1.0f;
+       }
+
+       int verticalResolution = 1;
+
+       _Util::FixedPoint26_6 fontSize;
+       fontSize.Reset(pFace->units_per_EM * expectedMaxHeight / (pFace->height * verticalResolution) - (1 / (2 * verticalResolution)));
+
+       return fontSize.ToFloat();
+}
+
 void
 _FontFt2::__CleanUp()
 {
index 8f3a72e..8cba5c6 100644 (file)
@@ -55,6 +55,8 @@ public:
 
        virtual _IFont::FontMapT* GetFallbackMap(void);
 
+       virtual float GetFontSizeFromMaxHeight(_Util::FixedPoint26_6 expectedMaxHeight) const;
+
        virtual bool IsEmoji(void) const;
 
 protected:
old mode 100755 (executable)
new mode 100644 (file)
index 2944b10..73155d2
@@ -102,31 +102,84 @@ Mutex* _MutexGuard::pMutexInstance = null;
 
 struct _FontCoordHolder
 {
-       _ResUtil::CoordHolder <int> size;
-       _ResUtil::CoordHolder <int> charSpace;
-       _ResUtil::CoordHolder <float> sizeF;
-       _ResUtil::CoordHolder <float> charSpaceF;
+       _ResUtil::CoordinateHolder <float, int> size;
+       _ResUtil::CoordinateHolder <float, int> charSpace;
 
        _FontCoordHolder()
+               : __pcBaseScale(1.0f)
+               , __vcBaseScale(1.0f)
        {
-               Reset(-1);
-               Reset(-1.0f);
+               _CoordinateSystem* pCoordinateSystem = _CoordinateSystem::GetInstance();
+
+               if (pCoordinateSystem)
+               {
+                       __pcBaseScale = pCoordinateSystem->GetTargetBaseScaleFactor();
+                       __vcBaseScale = pCoordinateSystem->GetAppBaseScaleFactor();
+               }
+
+               ResetFromVc(-1);
        }
 
-       void Reset(int _size)
+       void ResetFromVc(int intVcSize)
        {
-               size = _size;
-               charSpace = 0;
-               sizeF = static_cast<float>(_size);
-               charSpaceF = 0.0f;
+               this->ResetFromVc(static_cast<float>(intVcSize));
+               size.vcInt = intVcSize;
+               size.vcFloatActual = static_cast<float>(intVcSize);
+       }
+
+       void ResetFromVc(float floatVcSize)
+       {
+               size.vcInt = _FloatToIntForSize(floatVcSize);
+               size.pcInt = _FloatToIntForSize(static_cast<float>(__ConvertToPhyCoord(floatVcSize)));
+               size.vcFloat = floatVcSize;
+               size.vcFloatActual = size.vcFloat;
+
+               SetCharSpaceFromVc(0.0f);
+       }
+
+       void ResetFromPc(int intPcSize)
+       {
+               this->ResetFromPc(static_cast<float>(intPcSize));
+               size.pcInt = intPcSize;
+       }
+
+       void ResetFromPc(float floatPcSize)
+       {
+               size.vcInt = _FloatToIntForSize(static_cast<float>(__ConvertToVirCoord(floatPcSize)));
+               size.pcInt = _FloatToIntForSize(floatPcSize);
+               size.vcFloat = static_cast<float>(__ConvertToVirCoord(floatPcSize));
+               size.vcFloatActual = static_cast<float>(__ConvertToVirCoord(static_cast<double>(size.pcInt)));
+
+               SetCharSpaceFromVc(0.0f);
        }
 
-       void Reset(float _size)
+       void SetCharSpaceFromVc(int intVcSize)
        {
-               size = static_cast<int>(_size);
-               charSpace = 0;
-               sizeF = _size;
-               charSpaceF = 0.0f;
+               this->SetCharSpaceFromVc(static_cast<float>(intVcSize));
+               charSpace.vcInt = intVcSize;
+               charSpace.vcFloatActual = static_cast<float>(intVcSize);
+       }
+
+       void SetCharSpaceFromVc(float floatVcSize)
+       {
+               charSpace.vcInt = _FloatToIntForPos(floatVcSize);
+               charSpace.pcInt = _FloatToIntForPos(static_cast<float>(__ConvertToPhyCoord(floatVcSize)));
+               charSpace.vcFloat = floatVcSize;
+               charSpace.vcFloatActual = floatVcSize;
+       }
+
+private:
+       double __pcBaseScale;
+       double __vcBaseScale;
+
+       inline double __ConvertToPhyCoord(double val)
+       {
+               return val * __pcBaseScale / __vcBaseScale;
+       }
+
+       inline double __ConvertToVirCoord(double val)
+       {
+               return val * __vcBaseScale / __pcBaseScale;
        }
 };
 
@@ -205,7 +258,7 @@ _FontImpl::Construct(int style, int vcSize)
        result r = _pNativeFont->Construct(style, pcSize);
        SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Failed to construct _Font", GetErrorMessage(r));
 
-       _pCoordHolder->Reset(vcSize);
+       _pCoordHolder->ResetFromVc(vcSize);
 
        return E_SUCCESS;
 }
@@ -227,7 +280,7 @@ _FontImpl::Construct(const Tizen::Base::String& fontName, int style, int vcSize,
        result r = _pNativeFont->Construct(fontName, style, pcSize, isPathEnabled);
        SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Failed to construct _Font", GetErrorMessage(r));
 
-       _pCoordHolder->Reset(vcSize);
+       _pCoordHolder->ResetFromVc(vcSize);
 
        return E_SUCCESS;
 }
@@ -249,7 +302,7 @@ _FontImpl::Construct(const Tizen::Base::ByteBuffer& fontData, int style, int vcS
        result r = _pNativeFont->Construct(fontData, style, pcSize);
        SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Failed to construct _Font", GetErrorMessage(r));
 
-       _pCoordHolder->Reset(vcSize);
+       _pCoordHolder->ResetFromVc(vcSize);
 
        return E_SUCCESS;
 }
@@ -271,7 +324,7 @@ _FontImpl::Construct(int style, float vcSize)
        result r = _pNativeFont->Construct(style, pcSize);
        SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Failed to construct _Font", GetErrorMessage(r));
 
-       _pCoordHolder->Reset(vcSize);
+       _pCoordHolder->ResetFromVc(vcSize);
 
        return E_SUCCESS;
 }
@@ -293,7 +346,7 @@ _FontImpl::Construct(const Tizen::Base::String& fontName, int style, float vcSiz
        result r = _pNativeFont->Construct(fontName, style, pcSize, isPathEnabled);
        SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Failed to construct _Font", GetErrorMessage(r));
 
-       _pCoordHolder->Reset(vcSize);
+       _pCoordHolder->ResetFromVc(vcSize);
 
        return E_SUCCESS;
 }
@@ -315,7 +368,7 @@ _FontImpl::Construct(const Tizen::Base::ByteBuffer& fontData, int style, float v
        result r = _pNativeFont->Construct(fontData, style, pcSize);
        SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Failed to construct _Font", GetErrorMessage(r));
 
-       _pCoordHolder->Reset(vcSize);
+       _pCoordHolder->ResetFromVc(vcSize);
 
        return E_SUCCESS;
 }
@@ -632,7 +685,7 @@ _FontImpl::GetSize(void) const
        CRITICAL_SECTION;
        IF_NOT_CONSTRUCTED(return -1);
 
-       return _pCoordHolder->size.required;
+       return _FloatToIntForSize(_pCoordHolder->size.vcFloatActual);
 }
 
 float
@@ -641,7 +694,7 @@ _FontImpl::GetSizeF(void) const
        CRITICAL_SECTION;
        IF_NOT_CONSTRUCTED(return -1.0f);
 
-       return _pCoordHolder->sizeF.required;
+       return _pCoordHolder->size.vcFloatActual;
 }
 
 void
@@ -673,12 +726,9 @@ _FontImpl::SetCharSpace(int vcSpace)
        IF_NOT_CONSTRUCTED(return);
 
        // save it
-       _pCoordHolder->charSpace = vcSpace;
+       _pCoordHolder->SetCharSpaceFromVc(vcSpace);
 
-       // convert VC -> PC
-       int pcSpace = _ResUtil::ConvertToPhyCoordWidth(vcSpace);
-
-       _pNativeFont->SetCharSpace(pcSpace);
+       _pNativeFont->SetCharSpace(_pCoordHolder->charSpace.pcInt);
 
        return;
 }
@@ -690,12 +740,9 @@ _FontImpl::SetCharSpace(float vcSpace)
        IF_NOT_CONSTRUCTED(return);
 
        // save it
-       _pCoordHolder->charSpaceF = vcSpace;
-
-       // convert VC -> PC
-       float pcSpace = _ResUtil::ConvertToPhyCoordWidth(vcSpace);
+       _pCoordHolder->SetCharSpaceFromVc(vcSpace);
 
-       _pNativeFont->SetCharSpace(_FloatToIntForPos(pcSpace));
+       _pNativeFont->SetCharSpace(_pCoordHolder->charSpace.pcInt);
 
        return;
 }
@@ -706,7 +753,7 @@ _FontImpl::GetCharSpace(void) const
        CRITICAL_SECTION;
        IF_NOT_CONSTRUCTED(return 0);
 
-       return _pCoordHolder->charSpace.required;
+       return _pCoordHolder->charSpace.vcInt;
 }
 
 float
@@ -715,7 +762,7 @@ _FontImpl::GetCharSpaceF(void) const
        CRITICAL_SECTION;
        IF_NOT_CONSTRUCTED(return 0.0f);
 
-       return _pCoordHolder->charSpaceF.required;
+       return _pCoordHolder->charSpace.vcFloatActual;
 }
 
 Tizen::Base::String
@@ -771,6 +818,62 @@ _FontImpl::CloneN(const Font& font)
        return pFont.release();
 }
 
+Font*
+_FontImpl::CreateFontN(int style, float expectedMaxHeight)
+{
+       CRITICAL_SECTION;
+       SysTryReturn(NID_GRP, expectedMaxHeight > 0.0f, null, E_INVALID_ARG, "[E_INVALID_ARG] The specified max-height MUST be greater than 0.0f.");
+
+       _Util::FixedPoint26_6 pcSize(_ResUtil::ConvertToPhyCoordHeight(expectedMaxHeight));
+
+       std::auto_ptr<Font> pFont(new (std::nothrow) Font());
+       SysTryReturn(NID_GRP, pFont.get(), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
+
+       _FontImpl* pFontImpl = _FontImpl::GetInstance(*pFont);
+       SysTryReturn(NID_GRP, pFontImpl, null, E_SYSTEM, "[E_SYSTEM] Getting native font instance failed.");
+
+       result r = pFontImpl->_pNativeFont->Construct(style, _Util::FixedPoint26_6(expectedMaxHeight));
+       SysTryReturn(NID_GRP, r == E_SUCCESS, null, r, "[%s] _Font construct is failed.", GetErrorMessage(r));
+
+       _Util::CarveMagicKey(*pFontImpl, pFontImpl->_magicKey);
+       SysTryReturn(NID_GRP, pFontImpl->IsConstructed(), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
+
+       float fontPcSize = pFontImpl->_pNativeFont->GetFontSizeFromMaxHeight(pcSize);
+
+       pFontImpl->_pCoordHolder->ResetFromPc(fontPcSize);
+       pFontImpl->SetSize(pFontImpl->_pCoordHolder->size.vcFloat);
+
+       return pFont.release();
+}
+
+Font*
+_FontImpl::CreateFontN(const Tizen::Base::String& fontName, int style, float expectedMaxHeight)
+{
+       CRITICAL_SECTION;
+       SysTryReturn(NID_GRP, expectedMaxHeight > 0.0f, null, E_INVALID_ARG, "[E_INVALID_ARG] The specified max-height MUST be greater than 0.0f.");
+
+       _Util::FixedPoint26_6 pcSize(_ResUtil::ConvertToPhyCoordHeight(expectedMaxHeight));
+
+       std::auto_ptr<Font> pFont(new (std::nothrow) Font());
+       SysTryReturn(NID_GRP, pFont.get(), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
+
+       _FontImpl* pFontImpl = _FontImpl::GetInstance(*pFont);
+       SysTryReturn(NID_GRP, pFontImpl, null, E_SYSTEM, "[E_SYSTEM] Getting native font instance failed.");
+
+       result r = pFontImpl->_pNativeFont->Construct(fontName, style, _Util::FixedPoint26_6(expectedMaxHeight));
+       SysTryReturn(NID_GRP, r == E_SUCCESS, null, r, "[%s] _Font construct is failed.", GetErrorMessage(r));
+
+       _Util::CarveMagicKey(*pFontImpl, pFontImpl->_magicKey);
+       SysTryReturn(NID_GRP, pFontImpl->IsConstructed(), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
+
+       float fontPcSize = pFontImpl->_pNativeFont->GetFontSizeFromMaxHeight(pcSize);
+
+       pFontImpl->_pCoordHolder->ResetFromPc(fontPcSize);
+       pFontImpl->SetSize(pFontImpl->_pCoordHolder->size.vcFloat);
+
+       return pFont.release();
+}
+
 result
 _FontImpl::GetTextExtent(int vcWidth, const Tizen::Base::String& text, int startIndex, int length, bool outline, int& count, Dimension& vcDim) const
 {
@@ -878,7 +981,7 @@ _FontImpl::SetSize(int vcSize)
        IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED);
        SysTryReturnResult(NID_GRP, vcSize > 0, E_INVALID_ARG, "Font size should be greater than 0");
 
-       _pCoordHolder->Reset(vcSize);
+       _pCoordHolder->ResetFromVc(vcSize);
 
        // convert VC -> PC
        _Util::FixedPoint26_6 pcSize(_ResUtil::ConvertToPhyCoordHeight(vcSize));
@@ -887,8 +990,10 @@ _FontImpl::SetSize(int vcSize)
        {
                pcSize = _Util::FixedPoint26_6(1);
 
-               _pCoordHolder->size.phyCoord = 1;
-               _pCoordHolder->size.virCoord = vcSize;
+               _pCoordHolder->ResetFromPc(1);
+               _pCoordHolder->size.vcInt = vcSize;
+               _pCoordHolder->size.vcFloat = static_cast<float>(vcSize);
+               _pCoordHolder->size.vcFloatActual = _pCoordHolder->size.vcFloat;
        }
 
        result r = _pNativeFont->SetSize(pcSize);
@@ -904,7 +1009,7 @@ _FontImpl::SetSize(float vcSize)
        IF_NOT_CONSTRUCTED(return E_OPERATION_FAILED);
        SysTryReturnResult(NID_GRP, vcSize > 0.0f, E_INVALID_ARG, "Font size should be greater than 0");
 
-       _pCoordHolder->Reset(vcSize);
+       _pCoordHolder->ResetFromVc(vcSize);
 
        // convert VC -> PC
        _Util::FixedPoint26_6 pcSize(_ResUtil::ConvertToPhyCoordHeight(vcSize));
@@ -913,8 +1018,10 @@ _FontImpl::SetSize(float vcSize)
        {
                pcSize = _Util::FixedPoint26_6(1.0f);
 
-               _pCoordHolder->sizeF.phyCoord = 1.0f;
-               _pCoordHolder->sizeF.virCoord = vcSize;
+               _pCoordHolder->ResetFromPc(1.0f);
+               _pCoordHolder->size.vcInt = static_cast<int>(vcSize);
+               _pCoordHolder->size.vcFloat = vcSize;
+               _pCoordHolder->size.vcFloatActual = _pCoordHolder->size.vcFloat;
        }
 
        result r = _pNativeFont->SetSize(pcSize);
index 6a0ea05..8882ef3 100644 (file)
@@ -72,7 +72,7 @@ const int _DEFAULT_FONT_FACE = 0;
 const char* _DEFAULT_SYSTEM_FONT = "DefaultSystemFont";
 const char* _DEFAULT_SYSTEM_BOLD_FONT = "DefaultSystemBoldFont";
 const _Util::FixedPoint26_6 _SYSTEM_DEFAULT_FONT_SIZE(16);
-const int _BLACK_LIST_MAX_COUNT = 1000;
+const unsigned int _BLACK_LIST_MAX_COUNT = 1000;
 
 class _FontNull
        : public Tizen::Graphics::_IFont
@@ -128,6 +128,11 @@ public:
                return null;
        }
 
+       virtual float GetFontSizeFromMaxHeight(_Util::FixedPoint26_6 expectedMaxHeight) const
+       {
+               return 0.0f;
+       }
+
        virtual bool IsEmoji(void) const
        {
                return false;
index fbbb965..cb2ccf3 100644 (file)
@@ -162,6 +162,8 @@ public:
        //! Check if specified glyph is included.
        virtual unsigned long CheckGlyph(unsigned long character) = 0;
 
+       virtual float GetFontSizeFromMaxHeight(_Util::FixedPoint26_6 expectedMaxHeight) const = 0;
+
        //! Gets the support range and the property for this font engine.
        virtual bool GetFontSizeProperty(SizeProperty& sizeProperty) const = 0;
        virtual bool GetFontProperty(Property& property) const = 0;
index 6c17f00..f8bef1d 100644 (file)
@@ -1442,21 +1442,6 @@ ConvertToPhyCoordPointList(Tizen::Base::Collection::ArrayList& dest, const Tizen
 
 ////////////////////////////////////////////////////////////////////////////////
 
-template<typename T>
-struct CoordHolder
-{
-       T required;
-       T phyCoord;
-       T virCoord;
-
-       void operator =(const T& in)
-       {
-               required = in;
-               phyCoord = ConvertToPhyCoord(required);
-               virCoord = ConvertToVirCoord(phyCoord);
-       }
-};
-
 template<typename FloatType, typename IntType>
 struct CoordinateHolder
 {
old mode 100755 (executable)
new mode 100644 (file)
index b8b8d2d..f6d4738
@@ -129,6 +129,9 @@ public:
        _FontImpl* CloneN(void);
        static Font* CloneN(const Font& font);
 
+       static Font* CreateFontN(int style, float expectedMaxHeight);
+       static Font* CreateFontN(const Tizen::Base::String& fontName, int style, float expectedMaxHeight);
+
        /*
         * Gets the count and dimension of characters which can be get in the given width. @n
         *