Code Monkey home page Code Monkey logo

dtcoretext's Introduction

DTCoreText

This project aims to duplicate the methods present on Mac OSX which allow creation of NSAttributedString from HTML code on iOS.

The project covers two broad areas:

  1. Layouting - Interfacing with CoreText, generating attributed strings from HTML code
  2. User Interface - UI-related classes render these objects, specifically DTAttributedTextView, DTAttributedLabel and DTAttributedTextCell.

This is useful for drawing simple rich text like any HTML document without having to use a web view. For text selection and highlighting (as you might need for an Editor or Reader) there is the commercial DTRichTextEditor component which can be purchased in the Cocoanetics Parts Store.

Documentation

Documentation can be browsed online or installed in your Xcode Organizer via the Atom Feed URL.

A Q&A answers some frequently asked questions.

Changelog: GitHub Releases

There is also a Programming Guide with a set of solutions to common problems.

Follow @cocoanetics on Twitter or subscribe to the Cocoanetics Blog for news and updates.

License

It is open source and covered by a standard 2-clause BSD license. That means you have to mention Cocoanetics as the original author of this code and reproduce the LICENSE text inside your app.

You can purchase a Non-Attribution-License for 75 Euros for not having to include the LICENSE text.

We also accept sponsorship for specific enhancements which you might need. Please contact us via email for inquiries.

dtcoretext's People

Contributors

amro avatar batkuip avatar briandoig avatar cerupcat avatar cntrump avatar daniel-muhra-cw avatar dhoerl avatar dhoerl18 avatar farfromrefug avatar gshaviv avatar haowenwu avatar johnezang avatar jstart avatar kolyvan avatar kzaragoza avatar leehericks avatar liuslevis avatar logicality77 avatar mark0815 avatar odrobnik avatar rdougan avatar sanjodeundiak avatar sbeigel avatar seedotlee avatar soffes avatar tillawy avatar tomtaylor avatar tonycn avatar vaseltior avatar xuzhe 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  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

dtcoretext's Issues

HREFs split on several lines behave independently

If A HREF is line wrapped and broken in 2 glyph runs, there are two independent button created at the moment. Either DTLinkButton's highlight needs to be synched between instances from the same tag (not link), or the highlighting needs to be done through redrawing the all involved glyphruns in a different style.

Possibly make the HTML parsing two part

it might be easier to maintain in the future if the parsing would be in two parts:

  1. convert the HTML into a DOM, either with dictionaries and arrays or custom DOM classes.
  2. then create a custom drawn layout that still keeps some linkage with the original document.

Build Failed

i download NSAttributedString-Additions-for-HTML & DTWebArchive ,then build it:

2 errors:

Undefined symbols:
"OBJC_CLASS$_DTWebResource", referenced from:
objc-class-ref-to-DTWebResource in NSAttributedString+DTWebArchive.o
"OBJC_CLASS$_DTWebArchive", referenced from:
objc-class-ref-to-DTWebArchive in NSAttributedString+DTWebArchive.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

Implement 3.2 compatible Font Cache

Right now the only 4.0 dependency I am aware of is NSCache. I would like a wrapper, like DTCache that is basically passing through all caching to NSCache where available, but falls back to using NSMutableDictionary on 3.2. It would have to have a bit of heuristics to empty the cache in case of memory warning or maybe as well with ways to have items evicted after a while.

Nested lists not supported

While unordered lists (UL) seem to work fine, they don't nest properly. Try nesting a second <ul> tag inside of an <li> and it is handled poorly. The first <li> sub-bullet is rendered as part of the parent <li>, with subsequent bullets being handled as if they were part of the parent list. For example, use the HTML:

<ul>
<li>Unordered Lists <b>LI</b>
    <ul>
        <li>sublist 1</li>
        <li>sublist 2</li>
        <li>sublist 3</li>
    </ul></li>
</ul>

From a quick look at the parsing code in NSAttributedString+HTML.m, it looks like no concession has been made for nested structures. At a minimum, you'll need to keep track of the nesting level and know when you're opening a new list.

(I'm happy to help try and fix this, but don't want to duplicate effort if someone is already working on this.)

app is not able to handle data (base64) images in the <img> html tag

App currently does not handle non-url images in the html tag as it crashes.
Would like it to handle data images.

  • Sub

Image Handling

Some basic image handling has been implemented

Inline

Block

There is a known issue with images as blocks, outside of p tags.

An Image outside of P is treated as a paragraph

The previous image has float style. As a Workaround a newline is added after it until we can support floating in the layouting.

Supported Attributes

  • width, height in pixels
  • src with a local file path relative to the app bundle

Supported Image Formats

According to Apple the following image formats are supported for use with UIImage:

  • png
  • tif, tiff
  • jpeg, jpg
  • gif
  • bmp, bmpf
  • ico
  • cur
  • xbm

Paragraph spacing

Is there a way to set the paragraph spacing? Seems like it's always using the line height of the previous paragraph which looks bad in some situations.

Indention Problem with ul lists

Let github format this:

  • May I place an order by phone?

    In order for Lot18 to offer truly fair access to the limited availability of our products, all purchases must be made via our website.

  • What are my payment options?

    We accept payment from American Express, Visa, MasterCard, and Discover accounts with a billing address in the United States.

  • When will my order arrive?

                Our partners offer flat rate, ground shipping that ensures your order reaches you as quickly as possible, protected by product specific packing materials that protect your shipment in transit. In order to remain compliant with federal laws that govern the shipment of wine, please ensure that there is an adult available to sign for the delivery at the shipping address you specify. A valid ID may be required upon delivery.
            </p>
        </li>
        <li>
            <h3>Why was my order rejected?</h3>
            <p>
                Federal and state regulations have some restrictions on the states and counties that our partners are able to ship to.  In the event that we are not able to process your order, we will explain the reasons why, and will work with you to determine a more suitable solution, which may include using a different credit card or a second shipping address with an adult available to sign for the shipment.
            </p>
        </li>
        <li>
            <h3>How is sales tax calculated?</h3>
            <p>
                The sales tax quoted at checkout is based on the shipping address you provide. The amount includes both state and local taxes, when applicable.
            <p>
        </li>
    </ul>
    
    
    The library is not properly indenting paragraphs within list items. For example, all my list paragraphs have the first line begin at the left margin.:
    
            * List Item Title
    
    The paragraph text starts on the left border...
               then when it wraps its OK again ..
               and all other lines wrap properly
    
            * Next List Item Title
    
    
    
    
    

diacritics in a link word not clickable

I have an app using the DTAttributedTextView

some of my text has links with diacritics as shown below.

example

<p> Chestnuts are roasted, boiled, <a href='puréed' style='color:#545d62;font-weight:bolder;'>puréed</a> and preserved; used in both sweet and savoury dishes.</p> 

Normally a linked word activated the linkPushed: function which works with link without diacritics.

thanks
Kyle

Spaces in wrong place.

When parsing HTML with lots of <font> tags, spaces are misplaced, deleted or even added where they are not needed.

Arabic text rendering

Amazing work ...

I have noticed a minor issue when rendering Arabic text and it might be a core text issue. when rendering Arabic text it renders perfectly when not accented. if there are accents (َ ً ٌ ) it renders OK but some accents break the ligation, specifically this one ( ْ ).

That said you done amazing work and looking forward to the RT component.

Implement method to only do partial layouting and merge the results

If an image display size changes we can only re-layout the paragraph it is contained in and merge the resulting layout lines with an existing set of layout lines, shifting the lines below the image accordingly. This way we could avoid re-layouting the entire document.

Red flickering square when updating attributedString of DTAttributedTextView

Hi, I'm encountering some strange behavior when updating the DTAttributedTextView attributed string.

Here is how I reproduce it:

  1. Set up a DTAttributedTextView
  2. Add it as subview of a view's viewController
  3. Set the attributed string
  4. update the attributed string
  5. If the length of attribtued string changes, a red square flickers for few milliseconds over the textview

Thanks for your support.
Simone.

DTCoreTextFontDescriptor Performance

  • (CTFontRef)newMatchingFont :

// fast font creation
matchingFont = CTFontCreateWithFontDescriptor(fontDesc, pointSize, NULL);

This line takes forever, just did a quick Performance-Test with Instruments and this line took ~ 4.5 seconds on my iPhone 4.

<!doctype html> issue

Hello, I was doing some testing with your project, and I ran into what seems to be a bug. With the following (valid) html, it renders quite oddly.

<!doctype html>
<html>
<h2>NSAttributedString HTML Additions</h2>
(snip)
<h3>Please Help!</h3>
<p>If you find brief test cases where the created <font face="Courier" color="blue">NSAttributedString</font> differs from the version on OSX please send them to us!</p><p>Follow <a href="http://twitter.com/cocoanetics">@cocoanetics</a> on Twitter</p>
<p>This code is covered by a BSD License. &copy; 2011 Oliver Drobnik</p>
</html>

CATiledLayer fade

If you subclass CATiledLayer and override the fadeDuration class method to return 0.0 you can remove the fade effect on initial load and scrolling.

Unless, of course, that is the intented effect?

@"list-style" -> @"list-style-type"

In DTHTMLElement.m, this line:

NSString *listStyleStr = [[styles objectForKey:@"list-style"] lowercaseString];

should instead be:

NSString *listStyleStr = [[styles objectForKey:@"list-style-type"] lowercaseString];

Once I made this change then my lists got the proper bullets.

HTML text attributes not recognised for first element in HTML.

If you have html like this:

<html>
  <h1 style="text-align:center;">The Title</h1>
</html>

the centre attribute is not recognised.

However, if you put any other element before the one with an embedded style, then the issue goes away, and the text is properly centred; e.g.

<html>
  <br/>
  <h1 style="text-align:center;">The Title</h1>
</html>

UITableView extremely slow on loading

When using an UITableView with DTAttributedTextContentView I noticed it takes a long time to load when the user request the ViewController, and it seems is blocking the main thread, because the UI become unresponsive until the TableView has been loaded.

I'm testing on a 2nd generation iPodTouch with iOS 4.1.

Is there any workaround for improve performance?

Note that the html I'm using is very simple.

Thanks.

Too slow when loading long HTML

Thank you for your work!!!

I test lots of HTML files,
when parsing long html file, loading time is too long.... even more on my iPhone4, I can't load War and Peace sample file ;;;;

I'm a novice on objective-c, so that what's the problem..but what about using fast parser ???

Long Content will crash on iPad 1 but works fine on iPhone 4

Dose anyone else have the same problem?

You can try the <War & Peace> in the Demo (We should delete "Ranges" "Chars" "Data" "HTML" views as well, because they need very very much memories).

I got the Demo worked with no problem on iPhone 4 (very slow but still working) and crashed on iPad 1.
Since I don't have an iPad 2 yet, I have not tried it on iPad 2.

P.S. I also noticed before the Demo crashed on iPad 1, there is no memory warning in the log, so maybe the small memory of iPad 1 is not the real reason of crash.

Add async loading of non-local IMG

A UIImageView should be added that is able to download images asynchronously if an IMG reference is not to a local file. Since images can also be hyperlinked it needs to be a button and react with calling the URL.

DTAttributedTextCell contents overlap grouped table cell borders

When using DTAttributedTextCell in a grouped tableview, the contents of the cell will overlap the cell's border.

To see this behavior in action, just change the table style in the demo to UITableViewStyleGrouped: all of the borders will be overlapped (with the exclusion of the right-hand corners which look fine due to the fact the insets on the right hand side have been increased to make room for the disclosure indicator.

Rotation Support

If rotation is enabled on DemoTextViewController then the nav bar moves under the status bar on rotation.

&lt; not parsed.

In the HTML string passed through NSData to initWithHTML:documentAttributes: is &lt; which represents the less than sign (<). However the attributed string that is returned still contains &lt; rather than the less than sign which it should have been replaced with.

Text not properly redrawn if height not changed

Hi,

This can be reproduced in the demo by allowing the tableview containing all snippets to be displayed in all orientations.

The cells width is increased in landscape but none of the cell are redrawn so that the text will use the available width. To force the cell to be drawn using the full available width we have to change the height of the DTAttributedTextContentView.

Is this an expected behavior? If so, how should we use it to avoid the problem?

Thanks,
JF

Better Block versus Inline Handling

currently the handling to add a paragraph break after block respectively before new ones is still flaky.

Example: IMG outside of block, following block is to the right of it instead of below.

How do I use it?

I want to use this for a couple of my iOS apps, (one of which is on the app store. ) but there is a lack of documentation. I have read some of the blog posts but they aren't as descriptive as they could be. I need documentation that says this code does this, here's how to change the default font used to render text etc.

Potential leak in DTCoreTextLayouter

The -initWithAttributedString: code for DTCoreTextLayouter contains a bug that can leak the instantiated DTCoreTextLayouter if the attributedString argument is NULL.

The current code:

- (id)initWithAttributedString:(NSAttributedString *)attributedString
{
    if (!attributedString)
    {
        return nil;
    }

    if ((self = [super init]))
    {
        self.attributedString = attributedString;
    }

    return self;
}

This should be changed to something along the lines of (I've tried to match your coding / indent style):

- (id)initWithAttributedString:(NSAttributedString *)attributedString
{
    if ((self = [super init]))
    {
        if (!attributedString)
        {
            [self autorelease];
            return nil;
        }
        self.attributedString = attributedString;
    }

    return self;
}

Crash in DTAttributedTextContentView dealloc

Run the demo app
click on the custom fonts cell
Click on the HTML button in the bar
Click the back button (labeled "Snippets")
Click on any other row in the table.

The app will now crash in DTAttributedTextContentView dealloc in what seems to be a memory bug, most likely on over release of something, but I still haven't managed to figure it out.

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.