Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Iss1068 merge #777

Merged
merged 3 commits into from over 2 years ago

1 participant

minggo
minggo
Collaborator

No description provided.

minggo minggo merged commit ef103d0 into from
minggo minggo closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
40 cocos2dx/platform/linux/CCImage_linux.cpp
@@ -11,6 +11,9 @@
11 11 #include "ft2build.h"
12 12 #include "CCStdC.h"
13 13 #include FT_FREETYPE_H
  14 +#ifdef USE_FONTCONFIG
  15 + #include <fontconfig/fontconfig.h>
  16 +#endif
14 17
15 18 #define szFont_kenning 2
16 19
@@ -32,6 +35,10 @@ class BitmapDC
32 35 iInterval = szFont_kenning;
33 36 m_pData = NULL;
34 37 reset();
  38 +
  39 +#ifdef USE_FONTCONFIG
  40 + libError |= ! FcInit();
  41 +#endif
35 42 }
36 43
37 44 ~BitmapDC() {
@@ -40,6 +47,9 @@ class BitmapDC
40 47 // if (m_pData) {
41 48 // delete m_pData;
42 49 // }
  50 +#ifdef USE_FONTCONFIG
  51 + FcFini();
  52 +#endif
43 53
44 54 }
45 55
@@ -311,6 +321,10 @@ bool CCImage::initWithString(
311 321 const char * pFontName/* = nil*/,
312 322 int nSize/* = 0*/)
313 323 {
  324 +#ifdef USE_FONTCONFIG
  325 + FcPattern *pat = NULL, *match = NULL;
  326 +#endif
  327 +
314 328 bool bRet = false;
315 329 do
316 330 {
@@ -318,7 +332,28 @@ bool CCImage::initWithString(
318 332
319 333 BitmapDC &dc = sharedBitmapDC();
320 334
  335 +#ifdef USE_FONTCONFIG
  336 + // convert pFontName into a fontconfig pattern
  337 + pat = FcNameParse( (FcChar8 *) pFontName );
  338 + CC_BREAK_IF( ! pat );
  339 +
  340 + // set pattern substitution
  341 + FcConfigSubstitute( 0, pat, FcMatchPattern );
  342 + FcDefaultSubstitute( pat );
  343 +
  344 + // look for a match
  345 + FcResult result;
  346 + match = FcFontMatch( 0, pat, &result );
  347 + CC_BREAK_IF( ! match );
  348 +
  349 + // gett result file name
  350 + FcValue v;
  351 + FcPatternGet( match, "file", 0, &v );
  352 + const char* pFullFontName = (const char*) v.u.s;
  353 + CC_BREAK_IF(! pFullFontName);
  354 +#else
321 355 const char* pFullFontName = CCFileUtils::fullPathFromRelativePath(pFontName);
  356 +#endif
322 357
323 358 CC_BREAK_IF(! dc.getBitmap(pText, nWidth, nHeight, eAlignMask, pFullFontName, nSize));
324 359
@@ -337,6 +372,11 @@ bool CCImage::initWithString(
337 372 dc.reset();
338 373 }while (0);
339 374
  375 +#ifdef USE_FONTCONFIG
  376 + if( pat ) FcPatternDestroy( pat );
  377 + if( match ) FcPatternDestroy( match );
  378 +#endif
  379 +
340 380 //do nothing
341 381 return bRet;
342 382 }
6 cocos2dx/proj.linux/Makefile
@@ -12,8 +12,9 @@ INCLUDES = -I.. \
12 12 -I../platform/third_party/linux/libpng \
13 13 -I../platform/third_party/linux/libxml2 \
14 14 -I../platform/third_party/linux/libjpeg
15   -
16   -DEFINES = -DLINUX
  15 +
  16 +# add -DUSE_FONTCONFIG if you want to use libfontconfig
  17 +DEFINES = -DLINUX
17 18
18 19 OBJECTS = ../actions/CCAction.o \
19 20 ../actions/CCActionCamera.o \
@@ -119,6 +120,7 @@ STATICLIBS = $(STATICLIBS_DIR)/libfreetype.a \
119 120 $(STATICLIBS_DIR)/libpng.a \
120 121 $(STATICLIBS_DIR)/libjpeg.a
121 122
  123 +# add -lfontconfig if you want to use libfontconfig
122 124 SHAREDLIBS = -lglfw -lGL
123 125
124 126 ####### Build rules

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.