From 0f4c5df9f45e71ac52c59e9d6022a1bce5c8183b Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Mon, 20 Jul 2015 21:14:45 +0200 Subject: [PATCH] Support Photos in RasterImage template 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 | 43 +++++++++++++++++++++++++++++++++- lib/external_templates | 12 ++++------ src/insets/ExternalSupport.cpp | 19 +++++++++++++-- src/insets/ExternalSupport.h | 3 ++- 4 files changed, 65 insertions(+), 12 deletions(-) diff --git a/lib/doc/Customization.lyx b/lib/doc/Customization.lyx index 12958ddd78..1b5f86684a 100644 --- a/lib/doc/Customization.lyx +++ b/lib/doc/Customization.lyx @@ -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 diff --git a/lib/external_templates b/lib/external_templates index 0eef01bdae..7eefbb67e9 100644 --- a/lib/external_templates +++ b/lib/external_templates @@ -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\")" diff --git a/src/insets/ExternalSupport.cpp b/src/insets/ExternalSupport.cpp index 6d009a5dd2..b5afc0c1d9 100644 --- a/src/insets/ExternalSupport.cpp +++ b/src/insets/ExternalSupport.cpp @@ -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 diff --git a/src/insets/ExternalSupport.h b/src/insets/ExternalSupport.h index 472b82ebc9..1000735fb9 100644 --- a/src/insets/ExternalSupport.h +++ b/src/insets/ExternalSupport.h @@ -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 -- 2.39.5