Graphic image saving in text editor? - objective-c

I am making a basic text editor from this tutorial here:
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/TextArchitecture/Tasks/TextEditor.html
My text editor can save, write, and open documents in RTF and TXT format, but cannot save graphics along with any text. Formatted text is saved, and the graphic does display when the window is open, but does not get saved.

You're almost there, you just need to implement a bit more in your app's Info.plist.
- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
{
NSData *data;
[self setString:[textView textStorage]];
NSMutableDictionary *dict =
[NSDictionary dictionaryWithObject:NSRTFTextDocumentType
forKey:NSDocumentTypeDocumentAttribute];
Notice that in the method which asks for the data to be saved to file, no matter what, it's set up to use NSRTFTextDocumentType rather than NSRTF*D*TextDocumentType. RTFD means RTF with attachments, which saves an .rtfd document which is actually a package/bundle (a folder that is presented to the user as if it were a single file). Saving as NSRTFTextDocumentType will effectively discard the stuff that can't fit into an RTF document, like the images.
After step 12 is the following:
At this stage of its development, your editor opens and saves documents only with an extension of ????. To enable your application to save and open documents with a recognized file type, you need to use Xcode to configure the document types settings in the application’s property list file in the Resources folder in Xcode. (The Xcode template names the file with your project name followed by -Info.plist.) You can edit this file in Xcode by selecting the file in the Groups & Files list and using the built-in editor. Click the disclosure triangles to edit the value of the first item under CFBundleTypeExtensions to the preferred extension for your document files.
For more information about property list files, see “Storing Document Types Information in the Application's Property List” in Document-Based Applications Overview. For complete details about application property lists, see Runtime Configuration Guidelines.
Basically, right now, you're being passed in a generic DocumentType in that data method shown above. Once you claim in your Info.plist that you can handle RTF and RTFD data (as 2 separate entries), you will be passed in a different value in that method, depending on what the user has chosen in the Format popup button in the NSSavePanel. You can check the value of the passed in type and then specify NSRTFTextDocumentType or NSRTFDTextDocumentType accordingly.
You can probably look at TextEdit's Info.plist to use as the basis of your Document types, though be sure to change the NSDocument subclass name to your own so the NSDocumentController knows what class to use.

maybe your images are not saved in the same directory?
for example if I create a rtf document with TextEdit it creates an folder called something.rtfd and contains the TXT.rtf and all the images.

Related

Disabling highlighting while previewing a PDF file with UIDocumentInteractionController

My app downloads a PDF file from a web server and stores it locally on the iOS device. I then display it to the user using a UIDocumentInteractionController which is declared as a property named "controller" in the .h file.
NSURL *urlToFileToPreview = [NSURL fileURLWithPath:pathToFile];
self.controller.URL = urlToFileToPreview;
[self.controller presentPreviewAnimated:YES]
This works perfectly, but the UIDocumentInteractionController preview provides the ability to highlight text and add comment boxes, and I can't find an example of how to save those annotations so that when the file is opened again they are persistent.
Since I already have the URL of where the file is stored in the device's Documents directory, it would be a simple matter to overwrite it, but I have no idea how to extract the "changed/highlighted" file once the user presses the done button.
Since I can't find a way to save the changed file I simply want to disable highlighting so that the user doesn't have the expectation that the changes they have made will be persistent.

Edit .blend file's Text only

http://www.blendswap.com/blends/view/73614
I have downloaded this and want to use my own text on it using Blender (or another program). It is not used for commercial purpose. When I open it, I get no option to edit text. I tried edit external and GIMP which failed.
the .blend file is binary and can only be opened inside of Blender, When you create text objects they are displayed as objects inside blender. You should be able to find the object by using the object browser section inside blender and changing it there. You may have to recreate the text object depending on how the author did the original.

Multirow PDFAnnotationTextWidget in Cocoa

I am trying to create an editable pdf annotation in pdfkit which is multirow. The user does not need to be able to create new rows, but I want the text to be displayed over the entire bounding box (i.e. on several lines).
However it seems that it uses a standard single line NSTextField when it is in editing mode. If I just could access that object I could change it to multiline but it seems that PDFAnnotationTextWidget does not expose this object.
https://developer.apple.com/library/mac/documentation/graphicsimaging/Reference/QuartzFramework/Classes/PDFAnnotationTextWidget_Class/Reference/Reference.html
Any ideas?
The only example I found is the example project for PDFKit from 2006, but it also only support single line annotations.
https://developer.apple.com/library/mac/samplecode/PDFAnnotationEditor/Introduction/Intro.html
If not possible, is there a way to create custom PDFKit annotations, and in that case, how?
It seems that there is no public method to access that NSTextField.
You can access it only swizzling some methods, like I did in this example (please note: the code has a lot of warnings because it's old)
In my example you can write multiple lines in the NSTextField, but when you exit editing mode all goes on a single line: there is a reason why Apple used a single line text field for Widget annotations, AFAIK Widget annotations in PDF supports only single line, but this is a limitation on the PDF annotations and not in the Apple SDK.
If you save the document after the annotation is added, you can access it from any other pdf editor...and in that case you will see only a single line (that is not an NSTextField but the own implementation of the pdf reader).
If you want to permit to the user to write text on multiple lines, and to visualize it over the PDF (but without the possibility for the other pdf readers to change your annotations), you have to subclass PDFAnnotation and create your own class.
In this case, have a look a the MyStampAnnotation file. You can create a similar class, inheriting from PDFAnnotation. When the user clicks on the annotation (in editing mode), add your own textfield, then write the text directly on the document using something like CGContextShowTextAtPoint in the drawWithBox: method

How do you edit the Info.Plist file

I'm trying to create a document-based application but the problem is that I don't know how to edit the Info.plist file in order to let the application open certain types of files. I've looked through the apple's "Document-Based Applications Overview" guide to help, but to no avail.
I want my application to open .txt files and .rtf files. My interface only has a simple text view.
Please help. Thanks
Edit:
Every time I compile my code, my app just loads, but it shows an alert panel saying "No Document could be created". And in the log it just says "The public.rtf type doesn't map to any NSDocumentClass."
As for my properties tab, I have "Text Document" for my CFBundleTypeName and "public.rtf" for my LSItemContentTypes.
simply click it in xcode.
you also have the option to show it in source code style (xml-like).
for that right.click in xcode the plist file -> "open as" -> "source code file" (or something like that".
The Document-Based Applications Overview has a section called Storing Document Types Information in the Application's Property List. In that section, they explain how to edit Info.plist so that it lists supported document types. Their example is TextEdit, which opens RTF and plain text files much like what you want.
To open the window depicted in Figure 1, double click your target in the project folder tree (under the Targets section) and select the Properties tab.
in info.plist
in CFBundleDocumentTypes Key add CFBundleTypeName and set its values as extension for example to add support for word file add DOC as its value
There is nice article about it

Cocoa Document-Based App: Change "Save" to "Save As" for Viewer-Only Filetypes

I have a Cocoa document-based app that (currently at least) functions as a basic text editor. It saves .txt, .rtf, and .rtfd, and loads those plus .doc and .docx. If I open a .doc or .docx file and edit it, then try to close, it reminds me to save, but the save option doesn't do anything since the application is only a viewer for those types of files. How can I make that function as "Save As" for types that can only be viewed, like .doc and .docx?
Override the saveDocumentWithDelegate::: in your customised NSDocument to the following:
- (void)saveDocumentWithDelegate:(id)delegate didSaveSelector:(SEL)didSaveSelector contextInfo:(void *)contextInfo
{
if (delegate != nil)
{
// use delegate or contextInfo to decide what operation you need to use...
[self runModalSavePanelForSaveOperation:NSSaveAsOperation
delegate:delegate
didSaveSelector:didSaveSelector
contextInfo:contextInfo];
}
else
{
[super saveDocumentWithDelegate:delegate
didSaveSelector:didSaveSelector
contextInfo:contextInfo];
}
}
By default the delegate is either an NSWindow on window close or NSDocumentController if you quit the application and the controller enumerates the windows for reviewing changes.
Not completely clear if you actually want to write the updated file after editing, or prevent editing and thus prevent the warning that the document has been modified.
To not see the Save warning, first you would want to set your document type role to "Viewer", if it happens to be "Editor". This is in the Target settings.
Then you need to
1. ensure that the contents of the document isn't changed, and/or
2. tell the document not to bother showing itself as dirty
However, if you want to allow editing and saving the document, you would have to write those files back in the proper format. That's non-trivial, except for the fact that the source code for TextEdit is available and included with Xcode. But from a cursory glance, it appears that NSDocument already supports .doc and .docx.
You will find the Project folder for TextEdit in /Xcode/Examples.