use freetype

This commit is contained in:
carlo morgantini 2013-07-12 12:39:47 -07:00
parent ea72e046c6
commit e4af13f1f6
9 changed files with 132 additions and 15 deletions

View File

@ -1 +1 @@
5849b6db4793caca0d24d7114bb5c2d694379b56 ec5e1afbe876b72e97277ce13b4b1f8b1835eaea

View File

@ -101,6 +101,10 @@ THE SOFTWARE.
#include "label_nodes/CCLabelBMFontNew.h" #include "label_nodes/CCLabelBMFontNew.h"
#include "label_nodes/CCStringTTF.h" #include "label_nodes/CCStringTTF.h"
// carloX
#include "label_nodes/CCFontRenderFreeType.h"
// layers_scenes_transitions_nodes // layers_scenes_transitions_nodes
#include "layers_scenes_transitions_nodes/CCLayer.h" #include "layers_scenes_transitions_nodes/CCLayer.h"

View File

@ -6,13 +6,16 @@
// //
// //
#ifndef _FontIOS_h #ifndef _FontFreetype_h
#define _FontIOS_h #define _FontFreetype_h
#include <CoreText/CTFont.h>
#include "CCFont.h" #include "CCFont.h"
#include "ft2build.h"
#include "CCStdC.h"
#include FT_FREETYPE_H
NS_CC_BEGIN NS_CC_BEGIN
class FontFreeType : public Font class FontFreeType : public Font

View File

@ -10,8 +10,27 @@
#include "CCTextImage.h" #include "CCTextImage.h"
#include "CCFontRenderFreeType.h" #include "CCFontRenderFreeType.h"
#include "ft2build.h"
#include "CCStdC.h"
#include FT_FREETYPE_H
NS_CC_BEGIN 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) unsigned char * FontRenderFreeType::preparePageGlyphData(TextPageDef *thePage, char *fontName, int fontSize)
{ {

View File

@ -19,6 +19,8 @@ public:
virtual ~FontRenderFreeType() {} virtual ~FontRenderFreeType() {}
virtual unsigned char * preparePageGlyphData(TextPageDef *thePage, char *fontName, int fontSize); virtual unsigned char * preparePageGlyphData(TextPageDef *thePage, char *fontName, int fontSize);
static void testRendering();
}; };

View File

@ -109,17 +109,19 @@ void StringTTF::setLineBreakWithoutSpace(bool breakWithoutSpace)
void StringTTF::setScale(float scale) void StringTTF::setScale(float scale)
{ {
Node::setScale(scale); Node::setScale(scale);
alignText();
} }
void StringTTF::setScaleX(float scaleX) void StringTTF::setScaleX(float scaleX)
{ {
Node::setScaleX(scaleX); Node::setScaleX(scaleX);
alignText();
} }
void StringTTF::setScaleY(float scaleY) void StringTTF::setScaleY(float scaleY)
{ {
Node::setScaleY(scaleY); Node::setScaleY(scaleY);
alignText();
} }
void StringTTF::alignText() void StringTTF::alignText()
@ -349,16 +351,14 @@ Sprite * StringTTF::getSpriteForChar(unsigned short int theChar, int spriteIndex
float StringTTF::getLetterPosXLeft( Sprite* sp ) float StringTTF::getLetterPosXLeft( Sprite* sp )
{ {
float scaleX = 1.0f; float scaleX = _scaleX;
return sp->getPosition().x * scaleX - (sp->getContentSize().width * scaleX * sp->getAnchorPoint().x); return sp->getPosition().x * scaleX - (sp->getContentSize().width * scaleX * sp->getAnchorPoint().x);
} }
float StringTTF::getLetterPosXRight( Sprite* sp ) float StringTTF::getLetterPosXRight( Sprite* sp )
{ {
float scaleX = 1.0f; float scaleX = _scaleX;
float retVal = 0; return sp->getPosition().x * scaleX + (sp->getContentSize().width * scaleX * sp->getAnchorPoint().x);
retVal = sp->getPosition().x * scaleX + (sp->getContentSize().width * scaleX * sp->getAnchorPoint().x);
return retVal;
} }
int StringTTF::getCommonLineHeight() int StringTTF::getCommonLineHeight()
@ -484,4 +484,72 @@ void StringTTF::setLabelContentSize(const Size &newSize)
setContentSize(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 NS_CC_END

View File

@ -31,7 +31,7 @@
NS_CC_BEGIN NS_CC_BEGIN
class StringTTF : public Node , public LabelTextFormatProtocol class StringTTF : public Node , public LabelTextFormatProtocol, public RGBAProtocol
{ {
public: public:
@ -40,7 +40,7 @@ public:
bool setText(char *pStringToRender, float lineWidth, TextAlignment alignment = kTextAlignmentLeft, bool lineBreakWithoutSpaces = false); bool setText(char *pStringToRender, float lineWidth, TextAlignment alignment = kTextAlignmentLeft, bool lineBreakWithoutSpaces = false);
// main interface
virtual void setAlignment(TextAlignment alignment); virtual void setAlignment(TextAlignment alignment);
virtual void setWidth(float width); virtual void setWidth(float width);
virtual void setLineBreakWithoutSpace(bool breakWithoutSpace); virtual void setLineBreakWithoutSpace(bool breakWithoutSpace);
@ -48,7 +48,22 @@ public:
virtual void setScaleX(float scaleX); virtual void setScaleX(float scaleX);
virtual void setScaleY(float scaleY); 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 // CCLabelTextFormat protocol implementation

View File

@ -1669,6 +1669,12 @@ LabelDyamicTest::LabelDyamicTest()
addChild(pTestString); addChild(pTestString);
pTestString->setPosition(Point(0, size.height/2)); pTestString->setPosition(Point(0, size.height/2));
// test freetype
FontRenderFreeType::testRendering();
} }
void LabelDyamicTest::draw() void LabelDyamicTest::draw()

View File

@ -1 +1 @@
a4fb641b06cb677ec70e75590817a11fdbd1822c cf5276283a0b42901ebfa9822cc1a0a7ad2a8663