Giter Site home page Giter Site logo

fontlabel's Introduction

Copyright © 2009 Zynga Game Networks.

All .ttf files in this project are from http://www.webpagepublicity.com/free-fonts.html

This project provides 4 classes and 2 categories which are used to render text in custom fonts.

ZFont
-----

ZFont is the equivalent of UIFont but for arbitrary fonts.

Note that UIFont reports a larger ascender for some fonts (including Helvetica) than ZFont does.
I do not know why this occurs. ZFont uses CoreGraphics to determine this information.

FontManager
-----------

FontManager is used to cache CGFontRef objects so you can look them up by name,
the same way that UIFont caches its internal font objects by name.

### Usage:

Call `-[FontManager loadFont:]` once for each font you care about, generally as part
of your application startup. You then look up the ZFont objects later
with `-[FontManager zFontWithName:]`. If you don't call `-loadFont:`, it will be called
automatically for you when you call `-zFontWithName:`.

NSString (FontLabelStringDrawing)
---------------------------------

This category is modeled after NSString (UIStringDrawing) and provides the basic mechanism
for drawing text in a given CGFontRef. It differs in three key areas from UIStringDrawing:

* Wrapping of sized/drawn strings properly character-wraps really long words that cannot fit
  on a single line by themselves even when the lineBreakMode is UILineBreakModeWordWrap.
  UIStringDrawing appears to behave incorrectly under the same circumstances.
* Only some line break modes are supported at the moment.
  Notably, Clip and Head/Middle truncation are not supported.
* UIFont reports a larger ascender for the system font (Helvetica) than ZFont.
  I cannot figure out why this is. This means UIStringDrawing/UILabel will size any text
  rendered in Helvetica with a taller bounding box than FontLabelStringDrawing.

Usage should be the same as the corresponding methods from UIStringDrawing.

ZAttributedString/ZMutableAttributedString
------------------------------------------

ZAttributedString is an implementation of an attributed string, patterned after
NSAttributedString from desktop Cocoa. The primary difference is ZMutableAttributedString
does not offer a -mutableString method.

ZAttributedString (ZAttributedStringDrawing)
--------------------------------------------

This category mimics NSString (FontLabelStringDrawing) but provides drawing primitives
for ZAttributedString instead. They should all work like their FontLabelStringDrawing
counterparts.

FontLabel
---------

This is a subclass of UILabel that draws text using a ZFont instead
of a UIFont. It uses FontLabelStringDrawing internally to do the heavy lifting.
Wrapping, tail truncation, and `-sizeToFit` work, as do the standard
`textAlignment`/`textColor` properties. A new `zAttributedText` property
has been added that allows for attributed string rendering.

The following properties are ignored:

* enabled
* font (use zFont instead)
* shadowColor
* shadowOffset

## TODO
- support more properties from UILabel

fontlabel's People

Contributors

fluff avatar lilyball avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

fontlabel's Issues

Crash using static library

Hi, if I use FontLabel inside a static library the class FontLabel crashes on line 156:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ZAttributedString sizeConstrainedToSize:lineBreakMode:numberOfLines:]: unrecognized selector sent to instance 0x633e670'

In another hand if I use FontLabel without static library, inside the main project, works great.

Any ideas?

There's a problem when I use it for Chinese

ZFont *zFont = [ZFont fontWithUIFont:[UIFont fontWithName:@"Helvetica" size:17]];
FontLabel *label4 = [[FontLabel alloc] initWithFrame:CGRectMake(10, 90, 200, 15)];
ZMutableAttributedString *str = [[ZMutableAttributedString alloc] initWithString:statics
                                                                      attributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                                  zFont, ZFontAttributeName, nil]];
[str addAttribute:ZForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(5, 3)];
[str addAttribute:ZForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(2, 3)];
label4.zAttributedText = str;
[str release];

It appear to be a mess..

2 Warnings regarding initWithIndex of ZAttributeRun init.

warning: incompatible Objective-C types 'struct NSMutableArray *', expected 'struct NSDictionary *' when passing argument 2 of 'initWithIndex:attributes:' from distinct Objective-C type

I haven't studied yer code in detail, but I think if you replace

  • (id)initWithIndex:(NSUInteger)idx attributes:(NSDictionary*)attrs
    with
  • (id)initWithIndex:(NSUInteger)idx attributes:(id)attrs

in ZAttributedString.m

and in ZAttributedStringPrivate.h

The warnings go away, is that an acceptable fix?

China - korea string tranform to square

Hi Kballard ,

First word thanks for your best stuff, FontLabel is best control to show string style i have seen.
some day ago i got this problem and want to show u
if i use china or korea or indian font it turn into square
example this string ジョーカー --> it turn in to some thing like that [][][][]
I use systemFont :
CFStringRef name = CFStringCreateWithCString(kCFAllocatorDefault, [[UIFont boldSystemFontOfSize:14].fontName UTF8String], kCFStringEncodingUTF8);
CGFontRef _cgFont = CGFontCreateWithFontName(name);
ZFont* font = [[ZFont alloc]initWithCGFont:_cgFont size:14];
CFRelease(name);
CFRelease(_cgFont);
ZMutableAttributedString *str = [[ZMutableAttributedString alloc] initWithString: user attributes:[NSDictionary dictionaryWithObjectsAndKeys: font, ZFontAttributeName, nil]];

i try with UILable and this problem not happend :(
Hope you can fix it Kballard !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.