First of all, this is an interrupted Project (although individuals may continue in the future, but at the company level it has ended), but the related content has been completed:
Read the RTF/rtfd file, edit (font, size, color), add an image, and save it.
(The following describes why you should select the RTF format for rich text editing)
In the project process, I still encountered a lot of problems and got some gains. Therefore, I recorded them together.
16:04:07
First of all, we need to know what type of RTF is, which can be retrieved from Microsoft's website or searched for “rtfv1.72.16.doc ".
The specification mainly contains some control words, keywords, and other things. We need to parse some common characters to ensure that most formats of RTF files can be displayed.
In the previous logs, I mentioned three categories of omnigroup. Here I will explain the following:
<Omniui/ouirtfreader. h>: Read the RTF/rtfd file to obtain the nsattributedstring object. (for iOS, you can use coretext to draw nsattributedstring)
<Omniui/ouieditableframe. h>: draws the nsattributedstring object to the view and implements the editing function (mainly implements iOS-related delegate, such as uikeyinput, uitextinputtraits, and editmenu)
<Omniui/ouirtfwriter. h>: saves the nsattributedstring object to the path file RTF/rtfd, which can be opened on Mac.
Here, we will first mention how Microsoft's RTF standard includes processing images. However, on Mac, if the RTF standard contains images, they will be saved in rtfd format. That is to say, the Mac does not fully support the RTF standard, but this is mainly because the image is not supported.
Rtfd is actually a bundle. It is essentially a folder, but it is presented as an object in front of the user. Generally, rtfd contains a "TXT. rtf" and image file.
"TXT. rtf" contains the following content:
{\ Rtf1 \ ANSI \ ansicpg1252 \ cocoartf1138 \ cocoasubrtf260
{\ Fonttbl \ F0 \ fswiss \ fcharset0 arialmt; \ F1 \ fswiss \ fcharset0 Helvetica; \ F2 \ fnil \ fcharset134 stheitisc-light;
}
{\ Colortbl; \ red255 \ green255 \ blue255 ;}
\ Paperw11900 \ paperh16840 \ margl1440 \ margr1440 \ vieww10800 \ viewh7200 \ viewkind0
\ Pard \ tx720 \ tx1440 \ tx2160 \ tx2880 \ tx3600 \ tx4320 \ tx5040 \ tx5760 \ tx6480 \ tx7200 \ tx7920 \ tx8640 \ pardirnatural
\ F0 \ fs48 \ CF0 1 \
\ Pard \ tx720 \ tx1440 \ tx2160 \ tx2880 \ tx3600 \ tx4320 \ tx5040 \ tx5760 \ tx6480 \ tx7200 \ tx7920 \ tx8640 \ pardirnatural
\ F1 \ fs24 \ CF0 {\ nextgraphic ipadappicon.png \ width1440 \ height1440
} Finally} \ pard \ tx720 \ tx1440 \ tx2160 \ tx2880 \ tx3600 \ tx4320 \ tx5040 \ tx5760 \ tx6480 \ tx7200 \ tx7920 \ tx8640 \ pardirnatural
\ F2 \ fs48 \ CF0 \
}
The keyword of the image is nextgraphic.
Therefore, we need to modify Reader/writer to add nextgraphic parsing.
Fortunately, Omni has provided excellent support for the common keyword of RTF, so the workload here is much reduced.
1reader modification:
Added the rtfd file path variable, because we need to obtain image data through the path;
In -(Void) _ Parsekeyword to add nextgraphic parsing.
The parsing process imitates Omni'sCodeYou can, note that the image is stored as an oatextattachment object and then
Add the value of the oaattachmentattributename attribute to the final nsattributedstring.
For details about this part, refer to the textedit example provided by Omni.
2writer modification:
You also need to add the file path;
Obtain the oaattachmentattributename attribute value and obtain the original data and name of the image. Write the image to the disk, add the name to "TXT. rtf", and save the image.
This part is based on Huludao.
The 3ouieditableframe part has not been changed much and can be expanded as needed.
The Edit function of 4rtf is as follows:
This version adds the style selection, that is, a page pops up after the style is selected somewhere, you can select the font and size, and then return. The entered characters are of the selected type.
Because ouieditableframe has an interface for getting the current character location, this part is implemented in personal code.
5cut/copy/paste:
Mainly include cut/copy/paste of the image.
Implement the ouieditableframe delegate method. Because uipasteboard can only store plist data, I store the selected text as a temporary rtfd file,
Then, when paste is used, it reads from this file and restores it to an nsattributedstring object.
6 others:
Ouieditableframe is added to uiscrollview, so that it can slide freely during editing. This function is not available in the Omni example, but
The text on the keyboard is displayed in due time.
In addition, after modifying the dependent database, select the corresponding schema and build it on the device. Otherwise, the database you used is still in the previous version during compilation.
The above is what I personally think is important in this project. In fact, the Omni library is very powerful but not very easy to understand, because there are few documents, there are not many places to ask for help, so it is far inferior to three20 with a mass base.
It took a lot of time to imitate his example. It would be very painful to study the code, but after clarifying the ideas, I felt suddenly enlightened, in particular, it is found that Omni is very modular and easy to expand and customize.
However, there are many areas that are not clearly understood. For example, the app entry function provided in the example is not found, and how to use its well-known memory viewing function.
There is another problem:
There is no result when generating the IPA of the ad hoc version. Xcode shows that archive is successfully generated, but archive is not generated. I searched for some methods online, but it was still fruitless. If you have any friends, please kindly advise.
Next, let's talk about the project itself:
At that time, the company wanted to add the document editing function to an app. The goal was to generate a file that was common on Mac, IOS, and windows. In addition, the file can be edited, changed the font size, and added images.
Because the app itself is free, we hope this function can be implemented in a simple way.
As a result, his eyes fell on the RTF.
However, I did not think that the water in the RTF editor was quite deep. When I searched for documents, I found that even Windows developers thought it was a headache.
As a result, the company eventually interrupted the project by using the RTF with images that cannot be used on the above platform.
09:03:41
Personal thinking:
1. During the preliminary investigation, we found that there were not many resources related to it, and many of the rich text editing functions often use this as a selling point of the paid App. No app provided this function for free.
Evernote is also rich text editing to some extent, but its file format is custom and can only be opened with Evernote.
2 As a free app, the rich text editing function is definitely a highlight, but considering the difficulty (because I am the only one responsible for development), it can be improved iteratively.
For example, you can edit rich text in text first, then upgrade to adding images, and then add stored files to common features on platforms.
3windows cannot correctly identify rtfd, so we can set the function to export a certain format, such as HTML, etc.
These are my personal thoughts on projects.