How to control the size of image attachments in a NSTextView - image

By default, in a NSTextView, image attachments are displayed at their actual resolution. For large images, this results in having only a small portion of the image displayed in the view. This doesn't look good and the user has to do lots of scrolling to enter text after the image.
For example, in the window below, you can't tell much about the image in the text view.
So the question is: how to scale down image attachments, so that they fit in the NSTextView?

You can find a few solutions for this on the internet, based on subclassing NSTextAttachmentCell, but by doing so, you lose a number of good behaviors provided for free by the NSTextView, like the creation of annotations in an attached image.
Actually there is a much simpler solution: to use a NSLayoutManager property named defaultAttachmentScaling that does exactly what we want.
In your code, set this property as in:
myTextView.layoutManager.defaultAttachmentScaling = NSImageScaleProportionallyDown;
and this is it: large images are now scaled to match the width of the text view.
For detailed information on this property, I suggest you read the comments in the header file NSLayoutManager.h.
Note for iOS developers: unfortunately, this property is not available on iOS.

Related

Is it possible to position image title/caption above the image in Asciidoctor

Currently, all image caption I have used are automatically placed before an image, despite me placing the caption before the image in the code.
For example,
[caption=]
.Simple diagram of data storage
image::user-guide/data-storage.png[width="600"]
Is there any way I can re-position the caption such that it appears above/before the image like how table titles are positioned above a table?
I assume you're using the standard HTML5 output of Asciidoctor. This can't be parameterized; the HTML will always render first the image and then the title element.
You could override the rendering of images in the HTML5 backend, or create your own backend to structure the output as you need.
In addition to #ahus1's answer, you might be able to achieve the presentation you desire by applying a custom stylesheet via docinfo files. See https://asciidoctor.org/docs/user-manual/#docinfo-file

how to display two different bitmap images in canoe?

I would like to display two different images in the panel based on event, example, for light on display one bit map image, And for light off display another bitmap image.
I already tried to browse the options in properties box there is not much information available regarding this, did anybody have solution for this issue?
Usually you would use a Switch/Indicator control and use a bitmap that includes all states in one image. See chapter "Assigning and Creating Bitmaps" in the manual.

Putting text on an image in Actionscript 3

I may be missing something obvious. I have large background images. I want to put some text on top of them. Currently the background image hides the text, I want the text on top of the background image.
I did some searches, and find plenty of information about including small images in text. That's not what I want to do. There is no relation between the image and the text. addChildAt() does not help. The background image has addChild before the text has addChild.
This is generally easy to do in other languages, which leads me to think I'm missing something. What is it?
Added in response to question: The background image and text are coming from different objects, which is why addChildAt does not work.

Mixing graphics in NSTextView?

I thought I read somewhere that there is a way to embed drawings or other non-text in a text view, but I can't find anything about it in the Apple documentation. Can anyone point me in the right direction? I'm trying to build an editor, not just a view. I'm imagining a special character in the underlying text, and based on text attributes, it would reserves some blank space in the text layout. ? Or maybe I need to layout blocks myself, using NSTextContainers and a custom NSView to flow text around graphics?
Take a look into the NSTextAttachment and NSTextAttachmentCell. You can do your own custom drawing when you subclass the NSTextAttachmentCell.
Apple docs: Text Attachment Programming Topics

Cocoa: Creating a Custom Text View

In a nutshell, I don't want raw text, or even rich text. I want to load an xml document, which has metadata for sections of text, and I want to display that metadata in a drawer when I click on a given text section. A hyperlink is a good example; obviously trivial to do in a web app, but while I'm not that experienced with mac dev, I can't seem to find an easy way to accomplish this with cocoa.
Any suggestions as to general strategy? There doesn't seem to be an HTML view built in to Interface builder or I'd mess with that.
I'm not entirely clear on what you're trying to do. It sounds like you want to load an XML document, display the text, and display various metadata when certain bits of text are selected.
If that's the case, you should read about the Cocoa Text System. The NSTextStorage class is a subclass of NSMutableAttributedString, and you can apply arbitrary attributes to any range of text. When the selection changes, you can get the attributes in the selected range and use that to update your drawer. (By the way, drawers are really on their way out. I'd suggest a different user interface. NSSplitView-based interfaces are much more in vogue these days.)
Of course, to build up the NSTextStorage, you'd need to parse the XML with NSXMLDocument or NSXMLParser, but you'd get much more control and it would look more "Cocoa-like".
You could use a WebView, which is the Safari renderer, but I think you'd have a hard time getting it to display text the way you want. Safari has never been great at rendering XML without XSLT.

Resources