]> git.lyx.org Git - features.git/commitdiff
Support Photos in RasterImage template
authorGeorg Baum <baum@lyx.org>
Mon, 20 Jul 2015 19:14:45 +0000 (21:14 +0200)
committerGeorg Baum <baum@lyx.org>
Mon, 20 Jul 2015 19:14:45 +0000 (21:14 +0200)
Actually photos (i.e. .jpg files) where supported previously, but for pdflatex
output an unneeded conversion to png was done. The RasterImage templates
behaves now exactly as InsetGraphics for these files: If the input format is
jpg, use that for pdflatex, else convert to png.

lib/doc/Customization.lyx
lib/external_templates
src/insets/ExternalSupport.cpp
src/insets/ExternalSupport.h

index 12958ddd78c8982fc99415650e85da8f3d1b7098..1b5f86684a16897b0c5658cd9bceb466afc4915b 100644 (file)
@@ -1,5 +1,5 @@
 #LyX 2.2 created this file. For more info see http://www.lyx.org/
-\lyxformat 495
+\lyxformat 497
 \begin_document
 \begin_header
 \origin /systemlyxdir/doc/
@@ -24112,6 +24112,47 @@ $$Extension
 \end_inset
 
  The file extension (including the dot).
+\change_inserted -195340706 1437418878
+
+\end_layout
+
+\begin_layout Description
+
+\change_inserted -195340706 1437418878
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -195340706 1437418878
+$$pngOrjpg
+\end_layout
+
+\end_inset
+
+ This will be the string 
+\begin_inset Quotes eld
+\end_inset
+
+jpg
+\begin_inset Quotes erd
+\end_inset
+
+ if the file is in JPEG format, otherwise it will be the string 
+\begin_inset Quotes eld
+\end_inset
+
+png
+\begin_inset Quotes erd
+\end_inset
+
+.
+ This is useful to avoid uneeded conversions for output formats that support
+ both PNG and JPEG fomats.
+ The predefined RasterImage template uses this macro for the PDFLATeX output
+ format.
+\change_unchanged
+
 \end_layout
 
 \begin_layout Description
index 0eef01bdaee91af8bd845f52c9d2d0061ba99ea0..7eefbb67e91daa49da0e6dcfa93a8baba42dc759 100644 (file)
@@ -86,11 +86,7 @@ Template RasterImage
        # what the template can provide him with.
        HelpText
                A bitmap file.
-               Use this template to include bitmap images of any kind except
-               photos in JPEG format: These will be uncompressed by this
-               template, therefore it is better to include them with a
-               graphics inset, since the graphics inset preserves the
-               compression if the pdflatex compiler is used.
+               Use this template to include bitmap images of any kind.
        HelpTextEnd
        # ANY file type can be displayed as a RasterImage.
        # Specifically, LyX will attempt to interrogate the file itself
@@ -134,10 +130,10 @@ Template RasterImage
                TransformOption Extra  ExtraOption
                Option Arg "[$$Extra,$$Rotate,$$Resize,$$Clip]"
                Product "\\includegraphics$$Arg{$$AbsOrRelPathMaster$$Basename}"
-               UpdateFormat png
-               UpdateResult "$$AbsPath$$Basename.png"
+               UpdateFormat "$$pngOrjpg"
+               UpdateResult "$$AbsPath$$Basename.$$pngOrjpg"
                Requirement "graphicx"
-               ReferencedFile pdflatex "$$AbsPath$$Basename.png"
+               ReferencedFile pdflatex "$$AbsPath$$Basename.$$pngOrjpg"
        FormatEnd
        Format Ascii
                Product "$$Contents(\"$$AbsPath$$Basename.asc\")"
index 6d009a5dd2b13814d9bd7c0c3fdc092d860e7476..b5afc0c1d913294b8c24fb9dbf274bafb1e9ffe6 100644 (file)
@@ -83,6 +83,21 @@ string const doSubstitution(InsetExternalParams const & params,
                            bool external_in_tmpdir,
                            Substitute what)
 {
+       string result = s;
+       if (what != PATHS && contains(result, "$$pngOrjpg")) {
+               // This is for raster images and pdflatex:
+               // Since pdflatex supports both jpg and png, we choose the best format:
+               // jpg if the original file is jpg to retain the compression, else png.
+               string format = formats.getFormatFromFile(params.filename);
+               if (format == "jpg")
+                       result = subst(result, "$$pngOrjpg", "jpg");
+               else
+                       result = subst(result, "$$pngOrjpg", "png");
+       }
+
+       if (what == FORMATS)
+               return result;
+
        Buffer const * masterBuffer = buffer.masterBuffer();
        string const parentpath = external_in_tmpdir ?
                masterBuffer->temppath() :
@@ -94,7 +109,6 @@ string const doSubstitution(InsetExternalParams const & params,
                        onlyFileName(filename), string());
        string const absname = makeAbsPath(filename, parentpath).absFileName();
 
-       string result = s;
        if (what != ALL_BUT_PATHS) {
                string const filepath = onlyPath(filename);
                string const abspath = onlyPath(absname);
@@ -235,7 +249,8 @@ void updateExternal(InsetExternalParams const & params,
                        return; // FAILURE
        }
 
-       string const to_format = outputFormat.updateFormat;
+       string const to_format = doSubstitution(params, buffer,
+               outputFormat.updateFormat, false, external_in_tmpdir, FORMATS);
        if (to_format.empty())
                return; // NOT_NEEDED
 
index 472b82ebc94209a0a51a920d52412de6aa198a33..1000735fb9208cdaf3fedf11848152c6687fb08f 100644 (file)
@@ -37,7 +37,8 @@ void editExternal(InsetExternalParams const & params,
 enum Substitute {
        ALL,
        PATHS,
-       ALL_BUT_PATHS
+       ALL_BUT_PATHS,
+       FORMATS
 };
 
 /** Substitute meta-variables in string \p s, making use of \p params and