Giter Site home page Giter Site logo

liveui / ftcoretext Goto Github PK

View Code? Open in Web Editor NEW
782.0 45.0 125.0 1.2 MB

An open source Objective-C interface component that makes use of the CoreText framework to render static text content using a highly customisable markup syntax.

License: MIT License

Objective-C 98.80% Ruby 1.20%
objective-c html swift coretext ios

ftcoretext's Introduction

FTCoreText

An open source Objective-C interface component that makes use of the CoreText framework to render static text content using a highly customisable markup syntax.

FTCoreText \ FTCoreText \ FTCoreText inlined Base64-encoded images example screenshot

Usage

Implement FTCoreText into your project

Manually

  1. Download FTCoreText sources from repository
  2. Add files in FTCoreText folder to your project
  3. Include CoreText.framework in your project

Using CocoaPods

  1. Use FTCoreText pod

Use FTCoreTextView

1. Import FTCoreText

#import FTCoreTextView.h

2. Create an instance of FTCoreTextView

3. Create styles to apply to the output by creating instances of FTCoreTextStyle

//  Draw text closed in <red> tag in red color
//  Example: <red>this will be drawn red</red>
FTCoreTextStyle *redStyle = [FTCoreTextStyle styleWithName:@"red"];
redStyle.color = [UIColor redColor];

4. Once styles are defined, apply them to the view:

[ftCoreTextInstance addStyles:@[style1, style2, style3]];

5. Set text with corrent markdown to the FTCoreTextView instance

ftCoreTextInstance.text = @"My text with <red>red</red> word.";

See the included examples project highlighting various features.

Elements

FTCoreText provides some interface element types for rendering content types commonly found on the web and printed media such as lists, images, links and suchlike.

Included:

  • FTCoreTextTagDefault: the default style applied to the text.
  • FTCoreTextTagPage: Divide the text in pages. Markup: <_page/>
  • FTCoreTextTagBullet: define styles for bullets. Markup: <_bullet>content</bullet>.
  • FTCoreTextTagImage: renders images. Markup: <_image>imageNameOnBundle.extension</_image>
  • FTCoreTextTagLink: define style for links. Markup: <_link>link_target|link - name</_link>. See FTCoreTextViewDelegate for responding to touch.

To use the included element types, set the name of an FTCoreTextStyle style instance to one of the string constant types above and use the markup specified. Example: linkTypeFTCoreTextStyleInstance.name = FTCoreTextTagLink, and in the static content: <_link>http://xprogress.com|xProgress</_link>

Notes

  1. Use of the CoreText framework is available for iOS versions 3.2 and above.

  2. Although FTCoreTextView uses a similar markup syntax to HTML, most of the properties defined in the HTML specification are unsupported.

Contact

FTCoreText is developed by LiveUI & manGoweb. Please drop us an email to let us know you how you are using this component.

License

Open Source Initiative OSI - The MIT License (MIT):Licensing [OSI Approved License] The MIT License (MIT)

Copyright (c) 2011-2018 LiveUI

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

ftcoretext's People

Contributors

algal avatar cescofry avatar rafiki270 avatar rokgregoric avatar stowy 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  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  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  avatar  avatar  avatar  avatar

Watchers

 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ftcoretext's Issues

Performance in UITableView

FTCoreText is very cool, but performance is really low in UITableView. I found two ways to improve it:

  1. Regular expressions use a lot of resources, so I've changed - (void)processText method:
    replaced
    tagRange = [processedString rangeOfString:regEx options:NSRegularExpressionSearch range:remainingRange];
    with
    NSRange openSign = [processedString rangeOfString:@"<"];
    NSRange closeSign = [processedString rangeOfString:@">"];
    if (openSign.location != NSNotFound && closeSign.location != NSNotFound) {
    tagRange = NSMakeRange(openSign.location, closeSign.location - openSign.location + 1);
    } else {
    tagRange.location = NSNotFound;
    }
  2. CTFontCreateFromUIFont is also very heavy, so I save CTFontRef into FTCoreTextStyle. Also I changed FTCoreTextStyle property to retain (in FTCoreTextNode).

Hope this helped.

How to create pages

Hi,
First of all thanks for this github.
Well I was just wondering how to create a pages.
I tried to add the tag but it still show all the text in the same page. As well as added code for the style;
//txt file
hey there new page < page/ >
I am on new page

//Style
FTCoreTextStyle *pageStyle = [FTCoreTextStyle styleWithName:@"_page"]; // using fast method pageStyle.name=FTCoreTextTagPage;
[result addObject:pageStyle];

Please guide me....
Thanks & Regards,
Zahur

Allow CSS-like link stylings

It would be nice if when on touchesBegan you could set an alternate style for that tag (like underlining, textColor change, etc), which then reverts on touchesEnded.

Links in centered text

I'm using a multiple line FTCoreTextview, with centered text and links that start on one line and continue on the next. The touchable area of the link seems to be calculated as if it's aligned to the left. This means that the second part of the link is unclickable - or very hard to click, depending on the distance of the left.
When I align to the left it works fine though.

let bullet tag define bullet glyph and separate, indented text style

Right now, the bullet tag defines one style that applies both to the bullet glyph and to the text associated with the bullet. For instance, font overrides bulletFont and color overrides bulletColor. After the following style, the bullet and the text are green and sixteen point:

FTCoreTextStyle *bulletStyle = [defaultStyle copy];
bulletStyle.name = FTCoreTextTagBullet;
bulletStyle.bulletFont = [UIFont fontWithName:@"TimesNewRomanPSMT" size:32.f];
bulletStyle.bulletColor = [UIColor orangeColor];
bulletStyle.bulletCharacter = @"❧";
bulletStyle.font = [UIFont fontWithName:@"Helvetica" size:16.0f];
bulletStyle.color = [UIColor greenColor];

It would be good if there could be two styles. Then you could use one font and colour for the bullet glyph (e.g., blue, Webdings) and the letter glyphs from another (e.g., black, Helvetica).

In addition, I may be wrong, but I think defining a separate style for the bullet text is necessary just to support the usual indentation of the non-initial lines of text associated with a list item, as it works for in HTML for instance. I'd be very interested in helping with this but I'm not sure where to start.

For instance, I am not sure how to use CoreText to produce this indentation style, or if what I've suggested is the approach that best fits the component's close fit to CoreText's own model

touched frame issues

I am using FTCoreTextView and have noticed two issues with the location of the link as received in the delegate function:

  • (void)coreTextView:(FTCoreTextView *)acoreTextView receivedTouchOnData:(NSDictionary *)data
    {
    ...
    CGRect touchedFrame = CGRectFromString([data objectForKey:FTCoreTextDataFrame]);
  1. The Y value is always too large, by about the font size. I may be miscalculating something, but that's what I'm seeing.
  2. If there are multiple links on a line, I always get the same frame.

I am using this in conjunction with a popup, so I really notice these issues. #1 I can work around, but #2 makes for an awkward UX.

(request) : be able to load remote images

Hi,
It would be awesome if we can load images remotely :) ! I tried to but it did not work. Maybe you can edit my code to implement it easier in the repo ? look at this : stackoverflow.com/questions/11927942/ios-core-text-loosing-context-when-drawing-image-inside-a-block

touchedFrame (CGRect) issue for two links (or more) in one text line

Hi,

If we have two links which are appearing in one text line, touchedFrame (CGRect) of these links are always the same value. This rect value is the rect value of the last link in the line. It seems that the rect of first links are overridden by the rect value of last link.

The issue has been also found at #19

Find some leaks

Leaked Object # Address Size Responsible Library Responsible Frame
__NSCFType,1 0x13d60dd0 48 Bytes ChildReadHD -[FTCoreTextView applyStyle:inRange:onString:]
Malloc 32 Bytes,1 0x13d60a50 32 Bytes ChildReadHD -[FTCoreTextView applyStyle:inRange:onString:]
Malloc 16 Bytes,1 0x13d60c60 16 Bytes ChildReadHD -[FTCoreTextView applyStyle:inRange:onString:]
Malloc 1.00 KB,2 < multiple > 2.00 KB ChildReadHD -[FTCoreTextView updateFramesetterIfNeeded]
__NSCFType,3 < multiple > 288 Bytes ChildReadHD CTFontCreateFromUIFont
__NSCFType,1 0x5e3ec10 96 Bytes ChildReadHD CTFontCreateFromUIFont
Malloc 1.00 KB,1 0x909aa00 1.00 KB ChildReadHD -[FTCoreTextView updateFramesetterIfNeeded]

On Long press the link App crashes

Oct 16 14:48:36 users-iPod AppName[10049] : -[__NSSetI objectForKey:]: unrecognized selector sent to instance 0x1e57fb70
Oct 16 14:48:36 users-iPod AppName[10049] : *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSSetI objectForKey:]: unrecognized selector sent to instance 0x1e57fb70'
*** First throw call stack:

allow different bullet tags

There's one default tag for bullets -- <_bullet>.

But I might want different kinds of bullet styles, which would require being able to define custom bullet tags. I could now workaround this by giving <_bullet> a different style in different FTCoreTextViews, but then I would not be able to mix different bullet styles in one view.

Performance against UIWebView

Although FTCoreText was not specifically created to substitute a UIWebView, some people asked me how it does compared to it.
The answer is I really do not know. So I set up a "Profiler" branch with all the convenient componentes to load the view first in FTCoreTExt and then in UIWebview. Once the view load you can see on the top left corner the number of characters loaded as a reference to how performance change with different text length.
It would be very helpful if someone can point out a way to do proper tests against it.

Cool class, but has issue in a UITableView

Hi,
cool class, very lean and does the job. I encountered a small issue when using this in a UITableView.
Some random text seemed to be highlighted as link. It seems the markers are not cleared properly, so I added
[self.markers removeAllObjects];

in the "processtext" method (class FTCoreTextView).

appending

Is there an appropriate way to append text into an existing FTCoreTextView? Should I be keeping a separate buffer of the text and calling -setText every time I append something new to the buffer? Or does there need to be an -appendText method on FTCoreTextView that handles things more efficiently internally?

wrong height when the root controller is a UINavigationController

I change the code in FTCoreTextAppDelegate.m:

    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:articleVC];
    [self.window setRootViewController:nav];

The FTCoreText only display part text,because it's frame height is wrong.

undefined tag

when text has the "<" or ">" characters in string, the code identify them as undefined tag but crash because it's not closed or not opened .... I solved it by ignoring the undefined tags and continue processing from location after it.

what do you think.

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.