General XMetaL Discussion

XMetaL Community Forum General XMetaL Discussion Dynamically hide images in large documents by default?

  • jodekirk

    Dynamically hide images in large documents by default?

    Participants 1
    Replies 2
    Last Activity 5 years, 5 months ago

    Sometimes I want to open a very large manual that has over 1,000 images. This causes XMetaL to take about 30 minutes to display anything. I can't close the document until it finishes opening, so it is faster to force XMetaL to Close using Task Manager.

    Is there a way to dynamically hide all images if there are more than 100 images in the document?
    If it skips loading all images for large docs it would open much faster. We use SVG and SVGZ images.

    Reply

    Derek Read

    Reply to: Dynamically hide images in large documents by default?

    If you know you are going to be opening this document the easiest way to do this would be to turn off the “show inline images” setting beforehand. That's in the Tools > Options dialog on the View tab.

    There is likely a way (I haven't tried to write the script code) to count the number of specific elements in a document after it has been opened and before it has been rendered but I don't know if there is a way to turn “show inline images” off through an API at that point.

    Reply

    Derek Read

    Reply to: Dynamically hide images in large documents by default?

    If you put the following into an event macro named On_Document_Open_Complete inside the document-level MCR file for your customization, or in an event macro named On_Application_Document_Open_Complete for an application-level MCR file (one in Startup) you will be part way there.

    [code] var nodes = ActiveDocument.getNodesByXPath(“//image”);
    var tooManyImagesForMe = 200;
    if(nodes.length > tooManyImagesForMe) {
    var response = Application.MessageBox(“This document has a lot of images.nWould you like to disable image rendering?nn(this is a global setting that affects all documents)”,36);
    if(response == 6) { //6 = yes
    //turn “show inline images” off
    Application.IniVariable(“show_inline_images”) = “false”;
    }
    }[/code]

    Answers to some (anticipated) questions:

    1. This is using the global setting (as set in Tools > Options on the View menu) and so it affects all documents, currently open or to be opened. User can turn it back on in Tools > Options.

    2. You might want to re-enable the setting when the document is closed. If not, the user needs to go into Tools > Options and enable it themselves. The logic for that might be to simply call Application.IniVariable("show_inline_images") = "true"; However, if you have two such documents open then, without additional logic, closing one would re-enable the setting and the other doc would then have its images rendered. So, you'd probably want to store another global variable somewhere that keeps track of how many such documents are open. Then when the last one is closed you would enable the setting (probably in the On_Document_Close event). Or you might provide a separate macro for the user to run to toggle the feature back on. You might also want to turn the setting back on when XMetaL Author shuts down.

    3. An alternative method for doing this, specifically for SVG or other image types that are not drawn natively, might be to add logic into the On_Should_Create event that tells XMetaL Author whether to run the code in On_Initialize for the ActiveX control that renders your SVG (which is probably Internet Explorer). This would then only affect SVG images. You would probably have a similar macro to what I've listed above, but instead of toggling inline images off it would just check how many of a given element there are (same logic as above) then set some variable you choose that means “don't draw SVG images for this document” (you may need to use the CustomDocumentProperties API to pass values between macros). Then your On_Should_Create macro could check to see if that value is set to “don't draw SVG images for this document” and if it is then On_Should_Create would be set to “false” (which means that On_Initialize won't run). The On_Should_Create will run very briefly for every image in the document, so it might be very slightly slower than turning show_inline_images off, but when compared to instantiating 1000 embedded copies if Internet Explorer it should

    Reply

  • You must be logged in to reply to this topic.

Lost Your Password?

Products
Downloads
Support