texlive[69527] Master: ppmcheckpdf (21jan24)

commits+karl at tug.org commits+karl at tug.org
Sun Jan 21 22:18:12 CET 2024


Revision: 69527
          https://tug.org/svn/texlive?view=revision&revision=69527
Author:   karl
Date:     2024-01-21 22:18:12 +0100 (Sun, 21 Jan 2024)
Log Message:
-----------
ppmcheckpdf (21jan24)

Modified Paths:
--------------
    trunk/Master/tlpkg/bin/tlpkg-ctan-check
    trunk/Master/tlpkg/libexec/ctan2tds
    trunk/Master/tlpkg/tlpsrc/collection-binextra.tlpsrc

Added Paths:
-----------
    trunk/Master/texmf-dist/doc/support/ppmcheckpdf/
    trunk/Master/texmf-dist/doc/support/ppmcheckpdf/README.txt
    trunk/Master/texmf-dist/doc/support/ppmcheckpdf/ppmcheckpdf.pdf
    trunk/Master/texmf-dist/doc/support/ppmcheckpdf/ppmcheckpdf.tex
    trunk/Master/texmf-dist/scripts/ppmcheckpdf/
    trunk/Master/texmf-dist/scripts/ppmcheckpdf/ppmcheckpdf.lua
    trunk/Master/tlpkg/tlpsrc/ppmcheckpdf.tlpsrc

Added: trunk/Master/texmf-dist/doc/support/ppmcheckpdf/README.txt
===================================================================
--- trunk/Master/texmf-dist/doc/support/ppmcheckpdf/README.txt	                        (rev 0)
+++ trunk/Master/texmf-dist/doc/support/ppmcheckpdf/README.txt	2024-01-21 21:18:12 UTC (rev 69527)
@@ -0,0 +1,4 @@
+Package: Convert PDF to PNG and compare PNG files after l3build
+Author: Jianrui Lyu <tolvjr at 163.com>
+Repository: https://github.com/lvjr/ppmcheckpdf
+License: The LaTeX Project Public License 1.3c


Property changes on: trunk/Master/texmf-dist/doc/support/ppmcheckpdf/README.txt
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: trunk/Master/texmf-dist/doc/support/ppmcheckpdf/ppmcheckpdf.pdf
===================================================================
(Binary files differ)

Index: trunk/Master/texmf-dist/doc/support/ppmcheckpdf/ppmcheckpdf.pdf
===================================================================
--- trunk/Master/texmf-dist/doc/support/ppmcheckpdf/ppmcheckpdf.pdf	2024-01-21 21:16:33 UTC (rev 69526)
+++ trunk/Master/texmf-dist/doc/support/ppmcheckpdf/ppmcheckpdf.pdf	2024-01-21 21:18:12 UTC (rev 69527)

Property changes on: trunk/Master/texmf-dist/doc/support/ppmcheckpdf/ppmcheckpdf.pdf
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/pdf
\ No newline at end of property
Added: trunk/Master/texmf-dist/doc/support/ppmcheckpdf/ppmcheckpdf.tex
===================================================================
--- trunk/Master/texmf-dist/doc/support/ppmcheckpdf/ppmcheckpdf.tex	                        (rev 0)
+++ trunk/Master/texmf-dist/doc/support/ppmcheckpdf/ppmcheckpdf.tex	2024-01-21 21:18:12 UTC (rev 69527)
@@ -0,0 +1,106 @@
+%  -*- coding: utf-8 -*-
+\documentclass[oneside,12pt]{article}
+\usepackage[a4paper,margin=2cm]{geometry}
+
+\newcommand*{\myversion}{2024B}
+\newcommand*{\mydate}{Version \myversion\ (\the\year-\mylpad\month-\mylpad\day)}
+\newcommand*{\mylpad}[1]{\ifnum#1<10 0\the#1\else\the#1\fi}
+
+\setlength{\parindent}{0pt}
+\setlength{\parskip}{4pt plus 1pt minus 1pt}
+
+\usepackage{codehigh}
+\usepackage{hyperref}
+\hypersetup{
+  colorlinks=true,
+  urlcolor=blue3,
+  linkcolor=green3,
+}
+
+\NewDocumentCommand\mypkg{m}{\textcolor{blue3}{\mbox{\ttfamily#1}}}
+\NewDocumentCommand\myopt{m}{\textcolor{brown3}{\mbox{#1}}}
+\NewDocumentCommand\mycmd{m}{\textcolor{green3}{\ttfamily\fakeverb{#1}}}
+\NewDocumentCommand\myfile{m}{\textcolor{purple3}{\mbox{#1}}}
+\NewDocumentCommand\myprg{m}{\textcolor{cyan3}{\mbox{#1}}}
+
+\begin{document}
+
+\title{\sffamily
+  \textcolor{green3}{The \texttt{ppmcheckpdf} tool}\\
+  {\large Convert PDF to PNG and compare PNG files after \texttt{l3build}}%
+}
+\author{%
+  Jianrui Lyu (tolvjr at 163.com)%
+  %\\\url{https://github.com/lvjr/ppmcheckpdf}
+}
+\date{\mydate}
+\maketitle
+
+The \mypkg{l3build} system is a useful and powerful tool for regression testing.
+With \mypkg{l3build} you normally print the contents of some boxes from \myfile{.lvt} files
+to corresponding \myfile{.tlg} files. Sometimes \LaTeX{} kernel or some package your package
+depends on adds a whatisit or \mycmd{\kern0pt}, and your test files will fail even if
+the PDF files look the same as before and are still correct.
+
+This \mypkg{ppmcheckpdf} tool provides an alternative way for regression testing:
+Instead of printing box contents in \myfile{.lvt} files, you could just convert PDF files
+to PNG files and compare PNG files after \mypkg{l3build} finishes its job.
+
+\section{Installation}
+
+Normally your TeX distribution will copy \myfile{ppmcheckpdf.lua} file to the correct folder
+when you install this tool. If a manual installation is needed, you could download
+\href{https://ctan.org/pkg/ppmcheckpdf}{\myfile{ppmcheckpdf.lua}}
+from CTAN and install it to \myfile{TEXMF/scripts/ppmcheckpdf/ppmcheckpdf.lua}.
+
+The \mypkg{ppmcheckpdf} tool uses \myprg{pdftoppm} program for image converting.
+This program is installed by default on MiKTeX. For TeX Live, you can install it by running
+\begin{codehigh}
+tlmgr install wintools.windows
+\end{codehigh}
+on Windows, or running
+\begin{codehigh}
+sudo apt-get install poppler-utils
+\end{codehigh}
+on Ubuntu/Debian Linux.
+
+\section{Usages}
+
+First create a \myfile{buildend.lua} file with the following lines in the folder of your package
+(next to \myfile{build.lua} file for \mypkg{l3build}):
+\begin{codehigh}
+kpse.set_program_name("kpsewhich")
+dofile(kpse.lookup("ppmcheckpdf.lua"))
+\end{codehigh}
+Then you could run the folllowing commands
+\begin{codehigh}
+l3build check
+texlua buildend.lua
+\end{codehigh}
+
+The first run of \mypkg{ppmcheckpdf} will save image and md5 files to \myfile{testfiles} folder,
+and the subsequent runs of it will compare new md5 values with existing md5 values.
+
+You could force \mypkg{ppmcheckpdf} to save new image and md5 files to \myfile{testfiles} folder
+by passing \myopt{save} option to it:
+\begin{codehigh}
+l3build check
+texlua buildend.lua save
+\end{codehigh}
+
+\section{Customizations}
+
+The \myprg{pdftoppm} program supports several types of image files.
+By default the \mypkg{ppmcheckpdf} tool will use \myfile{.png} file,
+and you could change it in \myfile{build.lua} file like this:
+\begin{codehigh}
+imgext = ".ppm"
+\end{codehigh}
+\begin{codehigh}
+imgext = ".pgm"
+\end{codehigh}
+\begin{codehigh}
+imgext = ".pbm"
+\end{codehigh}
+
+\end{document}


Property changes on: trunk/Master/texmf-dist/doc/support/ppmcheckpdf/ppmcheckpdf.tex
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: trunk/Master/texmf-dist/scripts/ppmcheckpdf/ppmcheckpdf.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/ppmcheckpdf/ppmcheckpdf.lua	                        (rev 0)
+++ trunk/Master/texmf-dist/scripts/ppmcheckpdf/ppmcheckpdf.lua	2024-01-21 21:18:12 UTC (rev 69527)
@@ -0,0 +1,164 @@
+#!/usr/bin/env texlua
+
+-- Description: Convert PDF to PNG and compare PNG files after l3build
+-- Copyright: 2024 (c)  Jianrui Lyu <tolvjr at 163.com>
+-- Repository: https://github.com/lvjr/ppmcheckpdf
+-- License: The LaTeX Project Public License 1.3c
+
+ppmcheckpdf_version = "2024B"
+ppmcheckpdf_date = "2024-01-21"
+
+--------------------------------------------
+---- source code from l3build.lua
+--------------------------------------------
+
+local lfs = require("lfs")
+
+local assert           = assert
+local ipairs           = ipairs
+local insert           = table.insert
+local lookup           = kpse.lookup
+local match            = string.match
+local gsub             = string.gsub
+
+kpse.set_program_name("kpsewhich")
+build_kpse_path = match(lookup("l3build.lua"),"(.*[/])")
+local function build_require(s)
+  require(lookup("l3build-"..s..".lua", { path = build_kpse_path } ) )
+end
+
+-----------------------------------------
+
+build_require("file-functions")
+
+release_date = "2021-04-26" -- for old build.lua file
+dofile("build.lua")
+
+build_require("variables")
+
+imgext = imgext or ".png"
+
+local md5 = require("md5")
+
+local function md5sum(str)
+  if str then return md5.sumhexa(str) end
+end
+
+local function filesum(name)
+  local f = assert(io.open(name, "rb"))
+  local s = f:read("*all")
+  f:close()
+  return md5sum(s)
+end
+
+local function readfile(name)
+  local f = assert(io.open(name, "rb"))
+  local s = f:read("*all")
+  f:close()
+  return s
+end
+
+local function writefile(name, sum)
+  local f = assert(io.open(name, "w"))
+  f:write(sum)
+  f:close()
+end
+
+local function getfiles(path, pattern)
+  local files = { }
+  for entry in lfs.dir(path) do
+    if match(entry, pattern) then
+     insert(files, entry)
+    end
+  end
+  return files
+end
+
+local function getimgopt(imgext)
+  local imgopt = ""
+  if imgext == ".png" then
+    imgopt = " -png "
+  elseif imgext == ".ppm" then
+    imgopt = " "
+  elseif imgext == ".pgm" then
+    imgopt = " -gray "
+  elseif imgext == ".pbm" then
+    imgopt = " -mono "
+  else
+    error("unsupported image extension" .. imgext)
+  end
+  return imgopt
+end
+
+local function pdftoimg(path, pdf)
+  cmd = "pdftoppm " .. getimgopt(imgext) .. pdf .. " " .. jobname(pdf)
+  run(path, cmd)
+end
+
+local function saveimgmd5(imgname, md5file, newmd5)
+  print("save md5 and image files for " .. imgname)
+  cp(imgname, testdir, testfiledir)
+  writefile(md5file, newmd5)
+end
+
+local function ppmcheckpdf(job)
+  local errorlevel
+  local imgname = job .. imgext
+  local md5file = testfiledir .. "/" .. job .. ".md5"
+  local newmd5 = filesum(testdir .. "/" .. imgname)
+  if fileexists(md5file) then
+    local oldmd5 = readfile(md5file)
+    if newmd5 == oldmd5 then
+      errorlevel = 0
+      print("md5 check passed for " .. imgname)
+    else
+      errorlevel = 1
+      print("md5 check failed for " .. imgname)
+      local imgdiffexe = os.getenv("imgdiffexe")
+      if imgdiffexe then
+        local oldimg = abspath(testfiledir) .. "/" .. imgname
+        local newimg = abspath(testdir) .. "/" .. imgname
+        local diffname = job .. ".diff.png"
+        local cmd = imgdiffexe .. " " .. oldimg .. " " .. newimg
+                    .. " -compose src " .. diffname
+        print("creating image diff file " .. diffname)
+        run(testdir, cmd)
+      elseif arg[1] == "save" then
+        saveimgmd5(imgname, md5file, newmd5)
+      end
+    end
+  else
+    errorlevel = 0
+    saveimgmd5(imgname, md5file, newmd5)
+  end
+  return errorlevel
+end
+
+local function main()
+  local errorlevel = 0
+  local pattern = "%" .. pdfext .. "$"
+  local files = getfiles(testdir, pattern)
+  for _, v in ipairs(files) do
+    pdftoimg(testdir, v)
+    pattern = "^" .. jobname(v):gsub("%-", "%%-") .. "%-%d+%" .. imgext .. "$"
+    local imgfiles = getfiles(testdir, pattern)
+    if #imgfiles == 1 then
+      local imgname = jobname(v) .. imgext
+      if fileexists(testdir .. "/" .. imgname) then
+        rm(testdir, imgname)
+      end
+      ren(testdir, imgfiles[1], imgname)
+      local e = ppmcheckpdf(jobname(v)) or 0
+      errorlevel = errorlevel + e
+    else
+      for _, i in ipairs(imgfiles) do
+        local e = ppmcheckpdf(jobname(i)) or 0
+        errorlevel = errorlevel + e
+      end
+    end
+  end
+  return errorlevel
+end
+
+local errorlevel = main()
+if os.type == "windows" then os.exit(errorlevel) end


Property changes on: trunk/Master/texmf-dist/scripts/ppmcheckpdf/ppmcheckpdf.lua
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Modified: trunk/Master/tlpkg/bin/tlpkg-ctan-check
===================================================================
--- trunk/Master/tlpkg/bin/tlpkg-ctan-check	2024-01-21 21:16:33 UTC (rev 69526)
+++ trunk/Master/tlpkg/bin/tlpkg-ctan-check	2024-01-21 21:18:12 UTC (rev 69527)
@@ -671,7 +671,7 @@
     polyglossia polyhedra polynom polynomial
     polytable poormanlog postage postcards poster-mac postit postnotes
     powerdot powerdot-fuberlin powerdot-tuliplab
-    ppr-prv ppt-slides pracjourn practicalreports
+    ppmcheckpdf ppr-prv ppt-slides pracjourn practicalreports
     precattl prelim2e preprint prerex present
     pressrelease prettyref prettytok preview prftree
     principia printlen proba probsoln prociagssymp

Modified: trunk/Master/tlpkg/libexec/ctan2tds
===================================================================
--- trunk/Master/tlpkg/libexec/ctan2tds	2024-01-21 21:16:33 UTC (rev 69526)
+++ trunk/Master/tlpkg/libexec/ctan2tds	2024-01-21 21:18:12 UTC (rev 69527)
@@ -3690,6 +3690,7 @@
  'pgfmolbio'		=> '\.lua$',
  'pax'			=> 'pax.jar$',
  'placeat'              => '\.lua$',
+ 'ppmcheckpdf'		=> '\.lua$',
  'pst-pdf'		=> '\.bat(.w95)?$',
  'puyotikz'		=> '\.py$',
  'pythontex'            => '([23]|_.*)\.py$',

Modified: trunk/Master/tlpkg/tlpsrc/collection-binextra.tlpsrc
===================================================================
--- trunk/Master/tlpkg/tlpsrc/collection-binextra.tlpsrc	2024-01-21 21:16:33 UTC (rev 69526)
+++ trunk/Master/tlpkg/tlpsrc/collection-binextra.tlpsrc	2024-01-21 21:18:12 UTC (rev 69527)
@@ -78,6 +78,7 @@
 depend pfarrei
 depend pkfix
 depend pkfix-helper
+depend ppmcheckpdf
 depend purifyeps
 depend pythontex
 depend runtexshebang

Added: trunk/Master/tlpkg/tlpsrc/ppmcheckpdf.tlpsrc
===================================================================


More information about the tex-live-commits mailing list.