diff --git a/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id b/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id index 6f44a4858a..7ecded6ea1 100644 --- a/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -677964274bf46041ba92250007e73f13c206b537 \ No newline at end of file +bb1fa37ce8c92571a186d384fac845fcd218b10e \ No newline at end of file diff --git a/cocos2dx/label_nodes/CCFontFreeType.cpp b/cocos2dx/label_nodes/CCFontFreeType.cpp new file mode 100644 index 0000000000..9f8617614d --- /dev/null +++ b/cocos2dx/label_nodes/CCFontFreeType.cpp @@ -0,0 +1,279 @@ + + +#include +#include "cocos2d.h" +#include "CCFontFreeType.h" +#include "CCTextImage.h" + +NS_CC_BEGIN + +bool FontFreeType::createFontObject(const std::string &fontName, int fontSize) +{ + /* + CFStringRef theRefString = NULL; + theRefString = CFStringCreateWithCString(kCFAllocatorDefault, fontName.c_str(), CFStringGetSystemEncoding()); + NSString * fntName = [NSString stringWithUTF8String:fontName.c_str()]; + + // actually create iOS font (s) + _fontRef = CTFontCreateWithName(theRefString, fontSize, NULL); + _fontUI = [UIFont fontWithName:fntName size:fontSize]; + + return ( (_fontRef != NULL) && (_fontUI != NULL) ); + */ + + return false; +} + +FontFreeType::~FontFreeType() +{ + // release the font + // TO DO +} + +GlyphDef * FontFreeType::getGlyphsForText(const char *pText, int &outNumGlyphs) +{ + /* + float CHAR_PADDING = 10.0f; + + UniChar * characters; + CGGlyph * glyphs; + CFIndex count; + + CFStringRef lettersString; + lettersString = CFStringCreateWithCString(kCFAllocatorDefault, pText, kCFStringEncodingUTF8); + + if (NULL == lettersString) + return false; + + count = CFStringGetLength(lettersString); + + // Allocate our buffers for characters and glyphs. + characters = new UniChar[count]; + assert(characters != NULL); + + glyphs = new CGGlyph[count]; + assert(glyphs != NULL); + + // Get the characters from the string. + CFStringGetCharacters(lettersString, CFRangeMake(0, count), characters); + + // Get the glyphs for the characters. + CTFontGetGlyphsForCharacters(_fontRef, characters, glyphs, count); + CGGlyph *theFirstGlyph = &glyphs[0]; + + // get letters bounding boxes + CGRect *BBOx = new CGRect[count]; + assert(BBOx != NULL); + + + CTFontGetBoundingRectsForGlyphs(_fontRef, kCTFontHorizontalOrientation, theFirstGlyph, BBOx, count); + + GlyphDef *pGlyphs = new GlyphDef[count]; + assert(pGlyphs != NULL); + + + // sore result as CCRect + for (int c=0; c=newEnd ) + return 0; + + NSString * str = [NSString stringWithUTF8String:pText]; + if ( newEnd >= [str length]) + return 0; + + NSRange theRange; + + theRange.location = newBegin; + theRange.length = (newEnd - newBegin) +1; + + // trim the string + NSString *trimmedString = [str substringWithRange:theRange]; + + // ret the string + return [trimmedString UTF8String]; + */ + + return 0; +} + +int FontFreeType::getUTF8TextLenght(const char *pText) +{ + /* + CFStringRef lettersString = CFStringCreateWithCString(kCFAllocatorDefault, pText, kCFStringEncodingUTF8); + if (NULL == lettersString) + { + return 0; + } + + return CFStringGetLength(lettersString); + */ + return 0; +} + +NS_CC_END \ No newline at end of file diff --git a/cocos2dx/label_nodes/CCFontFreeType.h b/cocos2dx/label_nodes/CCFontFreeType.h new file mode 100644 index 0000000000..1d97e3b9f0 --- /dev/null +++ b/cocos2dx/label_nodes/CCFontFreeType.h @@ -0,0 +1,41 @@ +// +// CCFontIOS.h +// TestNewStringStuff +// +// Created by Carlo Morgantini on 5/20/13. +// +// + +#ifndef _FontIOS_h +#define _FontIOS_h + +#include + +#include "CCFont.h" + +NS_CC_BEGIN + +class FontFreeType : public Font +{ +public: + + virtual ~FontFreeType(); + virtual bool createFontObject(const std::string &fontName, int fontSize); + virtual int getUTF8TextLenght(const char *pText); + virtual Size getTextWidthAndHeight(const char *pText); + virtual GlyphDef * getGlyphsForText(const char *pText, int &outNumGlyphs); + virtual Size * getAdvancesForText(const char *pText, int &outNumLetters); + virtual Size * getAdvancesForTextUTF8(unsigned short *pText, int &outNumLetters); + virtual unsigned short int * getUTF8Text(const char *pText, int &outNumLetters); + virtual const char * trimUTF8Text(const char *pText, int newBegin, int newEnd); + +private: + + //CTFontRef _fontRef; + //void * _fontUI; + +}; + +NS_CC_END + +#endif diff --git a/cocos2dx/label_nodes/CCFontRenderFreeType.cpp b/cocos2dx/label_nodes/CCFontRenderFreeType.cpp new file mode 100644 index 0000000000..1c77df5c24 --- /dev/null +++ b/cocos2dx/label_nodes/CCFontRenderFreeType.cpp @@ -0,0 +1,102 @@ +// +// CCFontRenderIOS.mm +// TestNewStringStuff +// +// Created by Carlo Morgantini on 5/28/13. +// +// + +#include "cocos2d.h" +#include "CCTextImage.h" +#include "CCFontRenderFreeType.h" + +NS_CC_BEGIN + +unsigned char * FontRenderFreeType::preparePageGlyphData(TextPageDef *thePage, char *fontName, int fontSize) +{ + return 0; + /* + // constants + float LINE_PADDING = 1.9; + + if (!thePage) + return NULL; + + if (thePage->getNumLines() == 0) + return NULL; + + int pageWidth = thePage->getWidth(); + int pageHeight = thePage->getHeight(); + + // prepare memory ans set to 0 + int sizeInBytes = (pageWidth * pageHeight * 4); + unsigned char* data = new unsigned char[sizeInBytes]; + memset(data, 0, sizeInBytes); + + // prepare the context + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + CGContextRef context = CGBitmapContextCreate(data, pageWidth, pageHeight, 8, pageWidth * 4, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); + CGColorSpaceRelease(colorSpace); + + if (!context) + { + delete[] data; + return 0; + } + + // prepare the context + CGContextSetRGBFillColor(context, 1, 1, 1, 1); + CGContextTranslateCTM(context, 0.0f, pageHeight); + CGContextScaleCTM(context, 1.0f, -1.0f); //NOTE: NSString draws in UIKit referential i.e. renders upside-down compared to CGBitmapContext referential + + + UIGraphicsPushContext(context); + UITextAlignment align = NSTextAlignmentLeft; + + // create the font + NSString *nsFontName = [NSString stringWithUTF8String:fontName]; + id font = [UIFont fontWithName:nsFontName size:fontSize]; + + int numLines = thePage->getNumLines(); + for (int c = 0; cgetLineAt(c); + float lineHeight = pCurrentLine->getHeight(); + + float origX = LINE_PADDING; + float origY = pCurrentLine->getY(); + + int numGlyphToRender = pCurrentLine->getNumGlyph(); + + for (int cglyph = 0; cglyph < numGlyphToRender; ++cglyph) + { + GlyphDef currGlyph = pCurrentLine->getGlyphAt(cglyph); + + NSString *lineString = [NSString stringWithFormat: @"%C", currGlyph.getUTF8Letter()]; + CGRect tempRect; + + tempRect.origin.x = (origX - currGlyph.getRect().origin.x); + tempRect.origin.y = origY; + tempRect.size.width = currGlyph.getRect().size.width; + tempRect.size.height = lineHeight; + + // actually draw one character + [lineString drawInRect: tempRect withFont:font lineBreakMode:NSLineBreakByWordWrapping alignment:align]; + + // move to next character + origX += (tempRect.size.width + currGlyph.getPadding()); + } + } + + // clean everything + UIGraphicsPopContext(); + CGContextRelease(context); + + // everything looks good + return data; + + */ +} + + +NS_CC_END \ No newline at end of file diff --git a/cocos2dx/label_nodes/CCFontRenderFreeType.h b/cocos2dx/label_nodes/CCFontRenderFreeType.h new file mode 100644 index 0000000000..9cb8924206 --- /dev/null +++ b/cocos2dx/label_nodes/CCFontRenderFreeType.h @@ -0,0 +1,27 @@ +// +// CCFontRenderIOS.h +// TestNewStringStuff +// +// Created by Carlo Morgantini on 5/28/13. +// +// + +#ifndef _FontRenderFreeType_h +#define _FontRenderFreeType_h + +#include "CCFontRender.h" + +NS_CC_BEGIN + +class FontRenderFreeType : public FontRender +{ +public: + + virtual ~FontRenderFreeType() {} + virtual unsigned char * preparePageGlyphData(TextPageDef *thePage, char *fontName, int fontSize); + +}; + +NS_CC_END + +#endif diff --git a/cocos2dx/label_nodes/CCFontRenderIOS.h b/cocos2dx/label_nodes/CCFontRenderIOS.h index 10c1275259..4dd46dca5e 100644 --- a/cocos2dx/label_nodes/CCFontRenderIOS.h +++ b/cocos2dx/label_nodes/CCFontRenderIOS.h @@ -23,5 +23,5 @@ public: }; NS_CC_END - + #endif diff --git a/cocos2dx/platform/linux/CCImage.cpp b/cocos2dx/platform/linux/CCImage.cpp index ced8e117fb..d094ec918a 100644 --- a/cocos2dx/platform/linux/CCImage.cpp +++ b/cocos2dx/platform/linux/CCImage.cpp @@ -53,6 +53,7 @@ struct LineBreakLine { }; NS_CC_BEGIN + class BitmapDC { public: