From e4af13f1f619a2c4b7f5055ea562e660bbb6229a Mon Sep 17 00:00:00 2001 From: carlo morgantini Date: Fri, 12 Jul 2013 12:39:47 -0700 Subject: [PATCH] use freetype --- .../project.pbxproj.REMOVED.git-id | 2 +- cocos2dx/include/cocos2d.h | 4 + cocos2dx/label_nodes/CCFontFreeType.h | 11 ++- cocos2dx/label_nodes/CCFontRenderFreeType.cpp | 19 +++++ cocos2dx/label_nodes/CCFontRenderFreeType.h | 2 + cocos2dx/label_nodes/CCStringTTF.cpp | 80 +++++++++++++++++-- cocos2dx/label_nodes/CCStringTTF.h | 21 ++++- .../TestCpp/Classes/LabelTest/LabelTest.cpp | 6 ++ .../project.pbxproj.REMOVED.git-id | 2 +- 9 files changed, 132 insertions(+), 15 deletions(-) diff --git a/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id b/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id index 237ed63c41..cdc909db5b 100644 --- a/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -5849b6db4793caca0d24d7114bb5c2d694379b56 \ No newline at end of file +ec5e1afbe876b72e97277ce13b4b1f8b1835eaea \ No newline at end of file diff --git a/cocos2dx/include/cocos2d.h b/cocos2dx/include/cocos2d.h index f867fba136..e9dd1a0a4a 100755 --- a/cocos2dx/include/cocos2d.h +++ b/cocos2dx/include/cocos2d.h @@ -101,6 +101,10 @@ THE SOFTWARE. #include "label_nodes/CCLabelBMFontNew.h" #include "label_nodes/CCStringTTF.h" +// carloX +#include "label_nodes/CCFontRenderFreeType.h" + + // layers_scenes_transitions_nodes #include "layers_scenes_transitions_nodes/CCLayer.h" diff --git a/cocos2dx/label_nodes/CCFontFreeType.h b/cocos2dx/label_nodes/CCFontFreeType.h index 1d97e3b9f0..8555f8cd65 100644 --- a/cocos2dx/label_nodes/CCFontFreeType.h +++ b/cocos2dx/label_nodes/CCFontFreeType.h @@ -6,13 +6,16 @@ // // -#ifndef _FontIOS_h -#define _FontIOS_h - -#include +#ifndef _FontFreetype_h +#define _FontFreetype_h #include "CCFont.h" + +#include "ft2build.h" +#include "CCStdC.h" +#include FT_FREETYPE_H + NS_CC_BEGIN class FontFreeType : public Font diff --git a/cocos2dx/label_nodes/CCFontRenderFreeType.cpp b/cocos2dx/label_nodes/CCFontRenderFreeType.cpp index a11ffa4094..4d8f24a484 100644 --- a/cocos2dx/label_nodes/CCFontRenderFreeType.cpp +++ b/cocos2dx/label_nodes/CCFontRenderFreeType.cpp @@ -10,8 +10,27 @@ #include "CCTextImage.h" #include "CCFontRenderFreeType.h" +#include "ft2build.h" +#include "CCStdC.h" +#include FT_FREETYPE_H + NS_CC_BEGIN +FT_Library library; + +void FontRenderFreeType::testRendering() +{ + // begin freetype + //FT_Init_FreeType( &library ); + + + + // end freetype + //FT_Done_FreeType(library); + +} + + unsigned char * FontRenderFreeType::preparePageGlyphData(TextPageDef *thePage, char *fontName, int fontSize) { diff --git a/cocos2dx/label_nodes/CCFontRenderFreeType.h b/cocos2dx/label_nodes/CCFontRenderFreeType.h index 9cb8924206..ef13ffa119 100644 --- a/cocos2dx/label_nodes/CCFontRenderFreeType.h +++ b/cocos2dx/label_nodes/CCFontRenderFreeType.h @@ -19,6 +19,8 @@ public: virtual ~FontRenderFreeType() {} virtual unsigned char * preparePageGlyphData(TextPageDef *thePage, char *fontName, int fontSize); + static void testRendering(); + }; diff --git a/cocos2dx/label_nodes/CCStringTTF.cpp b/cocos2dx/label_nodes/CCStringTTF.cpp index 7087179f12..e32557f05f 100644 --- a/cocos2dx/label_nodes/CCStringTTF.cpp +++ b/cocos2dx/label_nodes/CCStringTTF.cpp @@ -109,17 +109,19 @@ void StringTTF::setLineBreakWithoutSpace(bool breakWithoutSpace) void StringTTF::setScale(float scale) { Node::setScale(scale); - + alignText(); } void StringTTF::setScaleX(float scaleX) { Node::setScaleX(scaleX); + alignText(); } void StringTTF::setScaleY(float scaleY) { Node::setScaleY(scaleY); + alignText(); } void StringTTF::alignText() @@ -349,16 +351,14 @@ Sprite * StringTTF::getSpriteForChar(unsigned short int theChar, int spriteIndex float StringTTF::getLetterPosXLeft( Sprite* sp ) { - float scaleX = 1.0f; + float scaleX = _scaleX; return sp->getPosition().x * scaleX - (sp->getContentSize().width * scaleX * sp->getAnchorPoint().x); } float StringTTF::getLetterPosXRight( Sprite* sp ) { - float scaleX = 1.0f; - float retVal = 0; - retVal = sp->getPosition().x * scaleX + (sp->getContentSize().width * scaleX * sp->getAnchorPoint().x); - return retVal; + float scaleX = _scaleX; + return sp->getPosition().x * scaleX + (sp->getContentSize().width * scaleX * sp->getAnchorPoint().x); } int StringTTF::getCommonLineHeight() @@ -484,4 +484,72 @@ void StringTTF::setLabelContentSize(const Size &newSize) setContentSize(newSize); } + +// RGBA protocol + + +bool StringTTF::isOpacityModifyRGB() const +{ + return false; +} + +void StringTTF::setOpacityModifyRGB(bool isOpacityModifyRGB) +{ +} + +unsigned char StringTTF::getOpacity() const +{ + return 0; +} + +unsigned char StringTTF::getDisplayedOpacity() const +{ + return 0; +} + +void StringTTF::setOpacity(GLubyte opacity) +{ +} +void StringTTF::updateDisplayedOpacity(GLubyte parentOpacity) +{ +} + +bool StringTTF::isCascadeOpacityEnabled() const +{ + return false; +} + +void StringTTF::setCascadeOpacityEnabled(bool cascadeOpacityEnabled) +{ +} + +const Color3B& StringTTF::getColor(void) const +{ + Color3B temp; + return temp; +} + +const Color3B& StringTTF::getDisplayedColor() const +{ + Color3B temp; + return temp; +} + +void StringTTF::setColor(const Color3B& color) +{ +} + +void StringTTF::updateDisplayedColor(const Color3B& parentColor) +{ +} + +bool StringTTF::isCascadeColorEnabled() const +{ + return false; +} + +void StringTTF::setCascadeColorEnabled(bool cascadeColorEnabled) +{ +} + NS_CC_END diff --git a/cocos2dx/label_nodes/CCStringTTF.h b/cocos2dx/label_nodes/CCStringTTF.h index a4b7fc2ed4..3eb1746843 100644 --- a/cocos2dx/label_nodes/CCStringTTF.h +++ b/cocos2dx/label_nodes/CCStringTTF.h @@ -31,7 +31,7 @@ NS_CC_BEGIN -class StringTTF : public Node , public LabelTextFormatProtocol +class StringTTF : public Node , public LabelTextFormatProtocol, public RGBAProtocol { public: @@ -40,7 +40,7 @@ public: bool setText(char *pStringToRender, float lineWidth, TextAlignment alignment = kTextAlignmentLeft, bool lineBreakWithoutSpaces = false); - + // main interface virtual void setAlignment(TextAlignment alignment); virtual void setWidth(float width); virtual void setLineBreakWithoutSpace(bool breakWithoutSpace); @@ -48,7 +48,22 @@ public: virtual void setScaleX(float scaleX); virtual void setScaleY(float scaleY); - + // RGBAProtocol + + virtual bool isOpacityModifyRGB() const; + virtual void setOpacityModifyRGB(bool isOpacityModifyRGB); + virtual unsigned char getOpacity() const; + virtual unsigned char getDisplayedOpacity() const; + virtual void setOpacity(GLubyte opacity); + virtual void updateDisplayedOpacity(GLubyte parentOpacity); + virtual bool isCascadeOpacityEnabled() const; + virtual void setCascadeOpacityEnabled(bool cascadeOpacityEnabled); + virtual const Color3B& getColor(void) const; + virtual const Color3B& getDisplayedColor() const; + virtual void setColor(const Color3B& color); + virtual void updateDisplayedColor(const Color3B& parentColor); + virtual bool isCascadeColorEnabled() const; + virtual void setCascadeColorEnabled(bool cascadeColorEnabled); // CCLabelTextFormat protocol implementation diff --git a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp index d058fdbd51..06a675e348 100644 --- a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp +++ b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp @@ -1669,6 +1669,12 @@ LabelDyamicTest::LabelDyamicTest() addChild(pTestString); pTestString->setPosition(Point(0, size.height/2)); + + + // test freetype + FontRenderFreeType::testRendering(); + + } void LabelDyamicTest::draw() diff --git a/samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id b/samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id index eda4c8ccec..f1f4415fcd 100644 --- a/samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -a4fb641b06cb677ec70e75590817a11fdbd1822c \ No newline at end of file +cf5276283a0b42901ebfa9822cc1a0a7ad2a8663 \ No newline at end of file