【问题标题】:Script to update bounding box in one EPS with values from another EPS使用来自另一 EPS 的值更新一个 EPS 中的边界框的脚本
【发布时间】:2012-12-17 00:26:48
【问题描述】:

我在 LaTeX 中创建了大量图像(主要是 pstricks)。其中一些图像构成了显示某些算法进程的序列的一部分。进程在图像中添加或删除内容,这会有效地影响图像大小,从而影响图像周围的边界框。

所以我想做的是有一个脚本(在任何命令行可调用语言中),它将提取一个文件的边界框组件(比如FileA.eps)并将它们替换为另一个文件的边界框组件文件(比如FileB.eps)。有时我只想为y-components 执行此操作,有时仅为x-components 执行此操作,有时仅为单个组件执行此操作(这取决于显示进度的顺序)。例如,考虑使用latex->dvips 序列创建的以下两个文件:

FileA.eps

%!PS-Adobe-2.0 EPSF-2.0 %%边界框:170 378 252 452 %%HiResBoundingBox:170.340 378.474 251.880 451.626 %%创建者:dvips(k) 5.992 版权所有 2012 Radical Eye Software ...

FileB.eps

%!PS-Adobe-2.0 EPSF-2.0 %%边界框:148 365 269 478 %%HiResBoundingBox:148.446 365.940 268.483 477.651 %%创建者:dvips(k) 5.992 版权所有 2012 Radical Eye Software ...

我想让FileA.eps 更新为

更新FileA.eps

%!PS-Adobe-2.0 EPSF-2.0 %%边界框:170 365 252 478 %%HiResBoundingBox:170.340 365.940 251.880 477.651 %%创建者:dvips(k) 5.992 版权所有 2012 Radical Eye Software ...

其中FileB.epsy 坐标用于替换原始FileA.eps 中的y 坐标。请注意,此更改适用于 %%BoundingBox%%HiResBoundingBox

理想情况下,我想要一些通用脚本 boundingboxscript 调用

[lang] boundinboxscript FileA.eps FileB.eps

其中[lang] 是语言(如perlruby),FileA.eps 是就地编辑的。本次讨论源于TeX, LaTeX & Friends chat room。我正在运行 Windows 7。

【问题讨论】:

    标签: regex shell latex bounding-box eps


    【解决方案1】:

    我对 perl 一无所知,但也许你可以转换这个 ruby​​ 脚本:

    outfile = ARGV[0]
    infile = ARGV[1]
    opts = ARGV[2]
    unless File.read(infile) =~ /%%BoundingBox: (\d+) (\d+) (\d+) (\d+)/
      puts "Invalid input file."
      exit!
    else
      x, y, w, h = $1, $2, $3, $4
      eps = File.read(outfile).sub(/%%BoundingBox: (\d+) (\d+) (\d+) (\d+)/) do
        x = $1 unless opts.include? "x"
        y = $2 unless opts.include? "y"
        w = $3 unless opts.include? "w"
        h = $4 unless opts.include? "h"
        "%%BoundingBox: #{x} #{y} #{w} #{h}"
      end
      File.write(outfile, eps)
    end
    

    调用:

    ruby boundinboxscript.rb FileA.eps FileB.eps xywh
    

    最后一个选项是您想从FileB.eps 中获取并放入FileA.eps

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多