aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/ImageSize.hs
AgeCommit message (Collapse)Author
2025-08-15ImageSize: Fix JPEG file signature detection.R. N. West
The previous implementation didn't include all possible JPEG file signatures. All signatures in the range of ff d8 ff e0 and ff d8 ff ef should be valid, in addition to ff d8 ff db (no application segment). See <https://gist.github.com/leommoore/f9e57ba2aa4bf197ebc5?permalink_comment_id=3863054#gistcomment-3863054> and p. 32 of <https://www.w3.org/Graphics/JPEG/itu-t81.pdf>.
2025-08-14ImageSize: Handle jpgs with signature FF D8 FF EE.John MacFarlane
Closes #11049.
2025-08-06ImageSize: Unpack compressed object streams in PDFs...John MacFarlane
...and look inside for MediaBox information. Closes #10902.
2025-07-29ImageSize: Add Point and Pica as constructors of ImageSize.John MacFarlane
[API change] This will prevent unnecessary conversion of units. Closes #8957.
2025-07-22T.P.ImageSize: support avif images.John MacFarlane
[API change] New Avif constructor on ImageType. Closes #10979.
2024-11-22Add WebP support to ImageSize (#10397)silby
Text.Pandoc.ImageSize: Add `Webp` constructor on ImageType. [API change]
2024-06-11T.P.ImageSize: don't prefer exif width/height when they conflict...John MacFarlane
...with width/height. That was a mistaken call in #6936. Usually when these values disagree, it is because the image has been resized by a tool that leaves the original exif values the same, so the width/height metadata are more likely to be correct that exif width/height. Closes #9871.
2024-04-25Update copyright dates to 2024.John MacFarlane
2024-04-16T.P.ImageSize: export `ImageSize` datatypeAlbert Krewinkel
2023-04-07ImageSize: drop BOM at start of SVG if present.John MacFarlane
Otherwise our code can fail to determine image size.
2023-01-10Update copyright years, it's 2023!Albert Krewinkel
2022-01-02Copyright notices: update for 2022Albert Krewinkel
2021-06-23ImageSize: Add Tiff constructor for ImageType.John MacFarlane
[Minor API change] This allows pandoc to get size information from tiff images. Closes #7405.
2021-02-16Rename Text.Pandoc.XMLParser -> Text.Pandoc.XML.Light...John MacFarlane
..and add new definitions isomorphic to xml-light's, but with Text instead of String. This allows us to keep most of the code in existing readers that use xml-light, but avoid lots of unnecessary allocation. We also add versions of the functions from xml-light's Text.XML.Light.Output and Text.XML.Light.Proc that operate on our modified XML types, and functions that convert xml-light types to our types (since some of our dependencies, like texmath, use xml-light). Update golden tests for docx and pptx. OOXML test: Use `showContent` instead of `ppContent` in `displayDiff`. Docx: Do a manual traversal to unwrap sdt and smartTag. This is faster, and needed to pass the tests. Benchmarks: A = prior to 8ca191604dcd13af27c11d2da225da646ebce6fc (Feb 8) B = as of 8ca191604dcd13af27c11d2da225da646ebce6fc (Feb 8) C = this commit | Reader | A | B | C | | ------- | ----- | ------ | ----- | | docbook | 18 ms | 12 ms | 10 ms | | opml | 65 ms | 62 ms | 35 ms | | jats | 15 ms | 11 ms | 9 ms | | docx | 72 ms | 69 ms | 44 ms | | odt | 78 ms | 41 ms | 28 ms | | epub | 64 ms | 61 ms | 56 ms | | fb2 | 14 ms | 5 ms | 4 ms |
2021-02-10Add new unexported module T.P.XMLParser.John MacFarlane
This exports functions that uses xml-conduit's parser to produce an xml-light Element or [Content]. This allows existing pandoc code to use a better parser without much modification. The new parser is used in all places where xml-light's parser was previously used. Benchmarks show a significant performance improvement in parsing XML-based formats (especially ODT and FB2). Note that the xml-light types use String, so the conversion from xml-conduit types involves a lot of extra allocation. It would be desirable to avoid that in the future by gradually switching to using xml-conduit directly. This can be done module by module. The new parser also reports errors, which we report when possible. A new constructor PandocXMLError has been added to PandocError in T.P.Error [API change]. Closes #7091, which was the main stimulus. These changes revealed the need for some changes in the tests. The docbook-reader.docbook test lacked definitions for the entities it used; these have been added. And the docx golden tests have been updated, because the new parser does not preserve the order of attributes. Add entity defs to docbook-reader.docbook. Update golden tests for docx.
2021-01-22ImageSize: use viewBox for svg if no length, width.John MacFarlane
This change allows pandoc to extract size information from more SVGs. Closes #7045.
2021-01-08Update copyright notices for 2021 (#7012)Albert Krewinkel
2020-12-14ImageSize: use exif width and height when available.John MacFarlane
After the move to JuicyPixels, we were getting incorrect width and heigh information for some images (see #6936, test-3.jpg). The correct information was encoded in Exif tags that JuicyPixels seemed to ignore. So we check these first before looking at the Width and Height identified by JuicyPixels. Closes #6936.
2020-12-13ImageSize: use JuicyPixels to extract size...John MacFarlane
...for png, jpeg, gif, instead of doing our own binary parsing. See #6936.
2020-12-13ImageSize: use JuicyPixels to determine png size.John MacFarlane
2020-11-23ImageSize: default to DPI 72 if the format specifies DPI of 0.John MacFarlane
This shouldn't happen, in general, but it can happen with JPEGs that don't conform to the spec. Having a DPI of 0 will blow up size calculations (division by 0). Closes #6880.
2020-03-15Use implicit Prelude (#6187)Albert Krewinkel
* Use implicit Prelude The previous behavior was introduced as a fix for #4464. It seems that this change alone did not fix the issue, and `stack ghci` and `cabal repl` only work with GHC 8.4.1 or newer, as no custom Prelude is loaded for these versions. Given this, it seems cleaner to revert to the implicit Prelude. * PandocMonad: remove outdated check for base version Only base versions 4.9 and later are supported, the check for `MIN_VERSION_base(4,8,0)` is therefore unnecessary. * Always use custom prelude Previously, the custom prelude was used only with older GHC versions, as a workaround for problems with ghci. The ghci problems are resolved by replacing package `base` with `base-noprelude`, allowing for consistent use of the custom prelude across all GHC versions.
2020-03-13Update copyright year (#6186)Albert Krewinkel
* Update copyright year * Copyright: add notes for Lua and Jira modules
2020-02-07More in-depth refactoring and cleanup (#6123)Joseph C. Sible
* Avoid duplicating the dash case * Pull common functions out of case branches * Make sure list lengths are only calculated once * Use unless * Simplify parseURIReference' and avoid an unnecessary call to length * Use <$> instead of reimplementing it * Use swap instead of reimplementing it * Remove eta-expansion that's been unnecessary since 90f5dd8 * Use tailDef instead of reimplementing it * Use second instead of fmap, per @tarleb
2019-11-12Switch to new pandoc-types and use Text instead of String [API change].despresc
PR #5884. + Use pandoc-types 1.20 and texmath 0.12. + Text is now used instead of String, with a few exceptions. + In the MediaBag module, some of the types using Strings were switched to use FilePath instead (not Text). + In the Parsing module, new parsers `manyChar`, `many1Char`, `manyTillChar`, `many1TillChar`, `many1Till`, `manyUntil`, `mantyUntilChar` have been added: these are like their unsuffixed counterparts but pack some or all of their output. + `glob` in Text.Pandoc.Class still takes String since it seems to be intended as an interface to Glob, which uses strings. It seems to be used only once in the package, in the EPUB writer, so that is not hard to change.
2019-03-21Improve pdfSize in ImageSize by ignoring all whitespace in /MediaBox command ↵richarddavis
(#5383) This fix ignores all whitespace in the PDF /MediaBox line so that a wider range of PDF sizes can be read. This improves fix to #4322.
2019-03-20Improve pdfSize in ImageSize.John MacFarlane
Improves fix to #4322.
2019-03-01Remove license boilerplate.John MacFarlane
The haddock module header contains essentially the same information, so the boilerplate is redundant and just one more thing to get out of sync.
2019-02-04Add missing copyright notices and remove license boilerplate (#5112)Albert Krewinkel
Quite a few modules were missing copyright notices. This commit adds copyright notices everywhere via haddock module headers. The old license boilerplate comment is redundant with this and has been removed. Update copyright years to 2019. Closes #4592.
2018-08-10Avoid non-exhaustive pattern matches.John MacFarlane
2018-08-10Avoid non-exhaustive pattern match.John MacFarlane
2018-08-10Avoid non-exhaustive pattern match.John MacFarlane
2018-03-18Use NoImplicitPrelude and explicitly import Prelude.John MacFarlane
This seems to be necessary if we are to use our custom Prelude with ghci. Closes #4464.
2018-03-17hlint fixes.John MacFarlane
2018-02-18EMF Image size support (#4375)Andrew Pritchard
2018-02-16Make image size detection for PDFs more robust.John MacFarlane
See #4322.
2018-02-03C -> c.John MacFarlane
2018-02-02Determine image size for PDFs.John MacFarlane
Closes #4322.
2018-01-17ImageSize: add derived Eq instance to DimensionJesse Rosenthal
2018-01-05Update copyright notices to include 2018Albert Krewinkel
2017-11-01hlintAlexander Krotov
2017-10-31Add Millimeter constructor to Dimension in ImageSize.John MacFarlane
Minor API change. Now sizes given in 'mm' are no longer converted to 'cm'. Closes #4012.
2017-10-27hlint suggestions.John MacFarlane
2017-06-02hlint suggestions.John MacFarlane
2017-05-25Allow em for image height/width in HTML, LaTeX.John MacFarlane
- Export `inEm` from ImageSize [API change]. - Change `showFl` and `show` instance for `Dimension` so extra decimal places are omitted. - Added `Em` as a constructor of `Dimension` [API change]. - Allow `em`, `cm`, `in` to pass through without conversion in HTML, LaTeX. Closes #3450.
2017-05-20Improve SVG image size code.Marc Schreiber
The old code made some unwise assumptions about how the svg file would look. See #3580.
2017-05-13Update dates in copyright noticesAlbert Krewinkel
This follows the suggestions given by the FSF for GPL licensed software. <https://www.gnu.org/prep/maintain/html_node/Copyright-Notices.html>
2017-04-16Read image size of Inkscape SVGs (#3580)schrieveslaach
2017-02-26ImageSize: export lengthToDim, new function scaleDimension.John MacFarlane
2017-02-22imageSize interface changemb21
`imageSize img` is now `imageSize opts img`