cocoanetics / dtcoretext Goto Github PK
View Code? Open in Web Editor NEWMethods to allow using HTML code with CoreText
License: BSD 2-Clause "Simplified" License
Methods to allow using HTML code with CoreText
License: BSD 2-Clause "Simplified" License
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.
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>
In the HTML string passed through NSData
to initWithHTML:documentAttributes:
is <
which represents the less than sign (<
). However the attributed string that is returned still contains <
rather than the less than sign which it should have been replaced with.
Sometimes text in DTAttributedTextContentView appears to be stretched/fuzzy. Please have a look at this screenshot: http://imageshack.us/f/716/screenshot20111031at104.png/ The DTAttributedTextContentViews there are not transformed in any way, I even turned off dequeuing of cells.
I'm using the latest commit: e8ae622
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
Either clear the CTRun with SUB or SUP and then redraw with baseline shifted up or down. Or if drawing all runs individually, then do the shifting at that time.
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
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.
Support right-to-left text flow as shown here: http://www.i18nguy.com/markup/right-to-left.html
also makes the underline "superscripted", for example with:
... up to 200 m2 on the...
A link that spans multiple lines only draws it's selection frame on the line that is tapped.
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.
Commit 2eb5dbb broke the automatic adjustment to the new width
At present HTML entities are not decoded. They should be.
App currently does not handle non-url images in the html tag as it crashes.
Would like it to handle data images.
Some basic image handling has been implemented
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.
According to Apple the following image formats are supported for use with UIImage:
The additional spacing after the last LI is applied to the second line of the following paragraph.
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.
// 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.
CGFontRef were available and could be used to load arabic a font from a file (XB Niloofar.ttf).
Please see: http://people.sabanciuniv.edu/recepkocur/customfont.zip
I can't find anything similar in NSAttributedString-Additions for HTML.
Was running the demo on the iPad 3.2 Simulator and found the images are all "squished"
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.)
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. © 2011 Oliver Drobnik</p>
</html>
When parsing HTML with lots of <font>
tags, spaces are misplaced, deleted or even added where they are not needed.
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.
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.
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;
}
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
this would allow usage of
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.
I have got some paragraph-text that get's displayed without issues. If I now do the following, to preserve line-breaks, only the text up until the first
gets displayed and then there is a very big break. Any ideas why?
Hi, I'm encountering some strange behavior when updating the DTAttributedTextView attributed string.
Here is how I reproduce it:
Thanks for your support.
Simone.
Add delegate methods to DTAttributedTextView that allow for interacting with URL-loading requests like UIWebView.
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.
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.
Let github format this:
In order for Lot18 to offer truly fair access to the limited availability of our products, all purchases must be made via our website.
We accept payment from American Express, Visa, MasterCard, and Discover accounts with a billing address in the United States.
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
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.
The subject says it all, its also visible in the demo app. Its even more noticable with larger font sizes and larger line height multiplicators.
Otherwise, awesome work!
Andi
Somebody should explore if parsing performance could be improved by using libxml to parse the document into an XML tree first and then recursively walk through the tree to build the attributed string.
An example of a wrapper around libxml can be found here: https://github.com/zootreeves/Objective-C-HMTL-Parser
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?
it might be easier to maintain in the future if the parsing would be in two parts:
...
continuing...
Then there won't be a space before 'continuing'.
Also there problably needs to be better spaces handling. HTML generally ignores multiple spaces. Newlines turn into spaces.
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.
I need to change default font size of text in DTAttributedTextView or DTAttributedTextContentView. I can change size using ' ' tag in the text. Can I change the Default font size to particular value by editing DTAttributedTextView or DTAttributedTextContentView?
Thanks in Advance,
Sanal MS
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 ???
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.
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.
If rotation is enabled on DemoTextViewController then the nav bar moves under the status bar on rotation.
image squashing bug is fixed, but image size is somewhat odd on iPhone 4.0 simulator.
And also,
one image is duplicated as a blank image !
check screenshot http://dl.dropbox.com/u/187600/ios4.0.tiff
Support for text-shadow properties
Basic text shadow support would be great. Multiple shadow even better.
Full definition of text-shadow property can be found here:
http://www.w3.org/TR/2010/WD-css3-text-20101005/#text-shadow
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.