Supporting Drop Caps in Text Kit - ios

I’m building an iOS reader app where I need to be able to highlight selections of text and optionally link notes with highlights. I’ve begun by using Text Kit (UITextView, NSAttributedString). I am targeting iOS 7, 8, and 9.
My problem is that I need to be able to support Drop Caps on certain paragraphs in the content. This means the first letter of a paragraph is the height of 2 lines of text and the first 2 lines of text appear beside it, then the remaining lines wrap under. My content has many drop cap characters on various paragraphs throughout.
Example showing 4-line drop cap.
Text Kit: Exclusion Paths
My initial assumption was that I would use Text Kit exclusion paths so that paragraph would wrap around it. But I can’t figure out a way to determine the exact placement of the exclusion paths and I wasn’t sure if these would float along as my content scrolls. With this approach, I would also have to manually handle text selection of the Drop Cap characters, which I’d like to avoid.
Text Kit: NSTextAttachments
I was hopeful that I could use inline Text Attachments (NSTextAttachment), but I can’t determine a way to have 2 lines wrap beside it.
Core Text
I found a couple older (pre-TextKit) examples of Drop Cap implementations using Core Text, however, every one showed only the first character of the content as a Drop Cap and not multiple paragraphs throughout the content as I need. I was hoping to avoid Core Text also since I’d rather not handle text selection manually.
https://stackoverflow.com/a/14469897
https://stackoverflow.com/a/14639864
https://stackoverflow.com/a/9272955
Current Hope/Question
NSTextAttachment feels like the simplest approach. Is there a way to wrap 2 lines of text beside it?
Fallback... I’m beginning to wonder if I should switch to WKWebView and drop iOS 7 -- since HTML supports drop caps and WKWebView provides more performance than UIWebView.

Related

Make bullet/num/check lists in UITextView

I am working on text editor app and using UITextView for this. Does anybody know how to make ability to do bullet/num/check lists in it? Any examples/tutorials?
Note: I need to do this as a part of text editor, so user can select some area, tap on according button and enable/disable lists formatting.
Based on my research for similar behavior (e.g. Bullet list and Numbered list in UITextView ), I would expect that there is no easy way to do it. I expect that you will have to use textView(_:shouldChangeTextIn:replacementText:) to hack currently added text to manually add bullets/numbers - e.g., if the user set that she currently wants to use unordered list, you will have to detect a new line added in shouldChangeTextIn and manually add there the bullet and indentation.
Another approach which you might consider (its applicability depends on your requirements) is to customize existing open source rich text editor. In my case I was able to get close enough to what I needed using RichEditorView, which uses HTML+CSS as an underlying technology (so to be able to do customizations, you need to know a bit about JavaScript, CSS and HTML).

implement select/cut/paste in TextArea

How can I implement the tradition menu items to copy / cut / paste / selectAll
in Codenameone TextArea
I can do these things if I happen to remember the keystrokes, but I don't
see any hooks to do them programmatically.
Since on-device editing is native the cut/copy/paste work thru touch and the menu will implicitly appear. So normally you wouldn't want to do this programmatically in Codename One, e.g. right now we don't have any API to get the currently selected text either since that concept is pretty different between platforms.
There are Display.copyToClipboard & Display.getPasteDataFromClipboard but those aren't for the text field selection purpose. They are rather for the use case of moving data within/between apps.

iOS sharing images with text in messages like Emoji

The goal is to be able to insert images with text when sharing text into an SMS Message from the App as well as in e-mails. Like it is in the picture below. When I try to share images with the UIActivityViewController the images appear on the next line and not next to the text. Is it possible to embed images in text and e-mail like the built in Emoji text?
The contents of text messages are just that, text (that is, a sequence of Unicode code points.) The emoji images you see in the screenshot come from a system font installed on all iOS devices, and are represented in the text as unicode code points, just like the other regular letters in the same message.
If you want to embed custom images into text fields in your app, you can create a custom font that includes the desired graphics (for some code points in the Unicode private use area,) include the font in your app as an asset, configure your text fields to use that font, and then provide some UI for the user to type those code points in.
But remember that this will only work on devices that have your custom font installed, and in apps that choose to use that custom font to display the text — so essentially only in your own app. So for example if you'd send the text in an email or iMessage/SMS to another device, your custom graphics would not work unless a) the receiving device has your custom font installed system-wide, and b) the app displaying the text resolves the Unicode private use area code points you chose to use for your images to this custom font of yours.
If you only want to embed images into text fields within your own app, on iOS 7 and later you can use the text attachments feature that TextKit supports.

iTextSharp - Pre filled Chinese characters in PDF do not come visible until textfield is focused

I am creating PDF with pre filled values in Chinese but when opening the PDF all the textfields containing Chinese text are empty. When focusing a textfield the Chinese text comes visible but is hided again when unfocusing the field. What could be the issue?
Please share some more info, as there could be more than one reason why the appearances aren't generated by iText.
A. The first reason is explained in the StackOverflow question "AcroForm values missing after flattening". In this case, the PDF contains a parameter that instructs iText not to generate appearances, which would explain why you don't see any value up until you click the field, in which case the viewer will create them.
B. The second reason is explained in section 8.3.3 (entitled "Text fields and fonts") of my book. In this case, the parameter in the PDF doesn't prevent the creation of field appearances, but iText fails to do so because you're not providing a font that knows how to display the Chinese characters.
See for instance figure 8.3 and 8.4 of the book.
In figure 8.3, you see that Chinese text isn't displayed in the upper window. By fixing the form (using two different strategies), the Chinese text appears in the lower two windows. Note that the Chinese text won't appear in all viewers in the case of the middle window.
In figure 8.4, you see that Korean text isn't displayed in the upper window, nor in the third window. In all other windows, different strategies were used to fix this problem:
It would lead us too far to discuss all the different strategies in an answer on SO. Instead, please take a look at the TextFontFields example (for the C# version, please take a look at the ported examples). My guess is that you'll benefit most from the AddSubstitutionFont() method, provided that you use a font of which a subset will be embedded in the document (in the example arialuni.ttf is used).
In case of A., the phenomenon also concerns other languages. In case of B., the parameter is correct, but you're not providing a font that can be used to generate the appearance.

Using Unicode characters with Delphi XE2

I'm looking at converting one of our applications to Delphi XE2 and generally take the opportunity to bring it up to date.
One of the features of the application is a StringGrid that displays a number of check marks in a couple of columns. To achieve this the grid is actually 2 aligned grids - the second of which is setup with the font as Wingdings in order to display the check marks.
Am I wrong in thinking that I should be able to use something like a TListView and use the checkmark char (U+2713) alongside the rest of the text... If so how the heck do I do this?
Do I need to set the font to Wingdings for that column? Does this need to be in OnDraw?
Am I barking up the wrong tree...
File->New->VCL Forms application
In the Component Palette, expand the Win32 tab and choose TListView, and drop it on the form.
Right-click the newly added TreeView1, and choose Items Editor... from the context menu.
Click New Item. Type in any text (for instance x Testing, using the 'x' as a placeholder for now).
Start the Windows Character Map application (Start button, type Chara in the search box, or Start->Programs->Accessories->Character Map). Change the font to Arial Unicode MS, and navigate to the character you want (it's in there).
Click the character, and then the Copy button. Switch back to the IDE, select the x placeholder you put in the edit, and hit Ctrl+V to paste the character you just chose from Character Map. You should now see your check mark (or whatever character you chose), followed by Testing.
(The steps above are the two-minute process I followed to find out how to do this, and that quick experiment showed that you could.)

Resources