diff options
author | Karl Berry <karl@freefriends.org> | 2012-12-04 00:09:42 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2012-12-04 00:09:42 +0000 |
commit | 0067f7a621d852e3dd89d9364753704c41f649d3 (patch) | |
tree | 829ba836083152e23df5ae44b08f6ec667622233 /Master/texmf-dist/tex | |
parent | 58281f233aa382e37f0e840e29a978aa95cc3f85 (diff) |
new latex package ocg-p (3dec12)
git-svn-id: svn://tug.org/texlive/trunk@28437 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r-- | Master/texmf-dist/tex/latex/ocg-p/ocg-p.sty | 270 |
1 files changed, 270 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/ocg-p/ocg-p.sty b/Master/texmf-dist/tex/latex/ocg-p/ocg-p.sty new file mode 100644 index 00000000000..9354753ab0c --- /dev/null +++ b/Master/texmf-dist/tex/latex/ocg-p/ocg-p.sty @@ -0,0 +1,270 @@ +% Copyright (C) 2012 by Werner Moshammer +% Parts of this code are Copyright (C) 2007 by Michael Ritzert <michael.ritz...@gmail.com> +% REPLACEMENT FOR THE OLD OCG.STY +% FOR PDFLATEX AND XELATEX (the old ocg.sys works only with pdflatex) +% This file may be distributed and/or modified under the LaTeX Project Public License + +\NeedsTeXFormat{LaTeX2e} +\def\ocgpversion{0.3} +\ProvidesPackage{ocg-p}[2012/12/01 v\ocgpversion\space Optional Content Group in a PDF document] + +\RequirePackage{eso-pic} +\RequirePackage{ifpdf} +\RequirePackage{ifxetex} + +\DeclareOption*{}\ProcessOptions*\relax %allow anything as option for the moment + + +\newif\if@ocgp@ifps + +\ifpdf + \ifnum\pdftexversion<120 + \PackageError{ocg-p}{% + pdfeTeX, version >= 1.20, required% + }{% + Install a newer version!% + }% + \fi +\else + \ifxetex + %already ok + \else + % dvips + \@ocgp@ifpstrue + \PackageWarningNoLine{ocg-p}{% + Only xelatex and pdflatex are supported% + }% + \fi +\fi + +\def\@ocgp@ocgHandle{\@auxout} + +\newif\if@ocgp@isnestedB\@ocgp@isnestedBfalse % nested OCG begin +\newif\if@ocgp@isnestedE\@ocgp@isnestedEfalse % nested OCG end + +\def\@ocgp@nestedB{% + \xdef\@ocgp@ocgorderlist{\@ocgp@ocgorderlist\space[} +} +\def\@ocgp@nestedE{% + \xdef\@ocgp@ocgorderlist{\@ocgp@ocgorderlist\space]} +} + + +\providecommand\ocg[3]{} % if running with ocgtools +\renewenvironment{ocg}[4][]{% + \if@ocgp@isnestedB% begin of nested ocg detected + \immediate\write\@ocgp@ocgHandle{% + \string\@ocgp@nestedB{}% + } + \fi + \global\@ocgp@isnestedBtrue % ocg begin + \global\@ocgp@isnestedEfalse % ocg end + + \if@filesw% + \immediate\write\@ocgp@ocgHandle{% + \string\@ocgp@newocg{#2}{#3}{#4}{#1}% + } + \fi + \gdef\@ocgp@curnum{#3}% + \ifpdf + \pdfliteral{/OC /OC\@ocgp@curnum\space BDC}% + \else + \if@ocgp@ifps % soon (not implemented yet) POSTSCRIPT + \special{ps: mark /OC /OC\@ocgp@curnum\space /BDC pdfmark}% + \else + \special{pdf: content /OC /OC\@ocgp@curnum\space BDC}% + \fi + \fi + \message{/OC\@ocgp@curnum}% + \ignorespaces +}{% + \ifpdf + \pdfliteral{EMC}% + \else + \if@ocgp@ifps % soon (not implemented yet) POSTSCRIPT + \special{ps: mark /EMC pdfmark}% + \else + \special{pdf: content EMC}% + \fi + \fi + \if@ocgp@isnestedE% end of nested ocg detected + \immediate\write\@ocgp@ocgHandle{% + \string\@ocgp@nestedE{}% + } + \fi + \global\@ocgp@isnestedEtrue % ocg end + \global\@ocgp@isnestedBfalse % ocg begin + \ignorespacesafterend +} + + +\def\@ocgp@ocglist{} +\def\@ocgp@ocgofflist{} +\def\@ocgp@ocgviewlist{} % to switch ocg off in layer toolbar of the viewer +\gdef\@ocgp@ocgmaplist{} +\def\@ocgp@ocgorderlist{} % ocgs in first-defined order + hierarchy + +% FUTURE PARAMETERS +% notprintable -> PrintState=OFF +% alwaysprinted -> Printstate=ON +% notinlayertoolbar (visiblity not changeable) -> not listed in /Order +% notexportable -> ExportState=OFF +% alwaysexported -> Exportstate=ON +% visible (same as bool-argument visible) -> ViewState=ON +% not visible (same as bool-argument visible) -> ViewState=ON + +% -> +% not visible AND alwaysprinted -> only on print + +\newcount\@ocgp@num\@ocgp@num=0 + +\def\@ocgp@newocg#1#2#3#4{% #1: OCG name, #2: OC id num, #3: visiblity on/off + \expandafter\ifx\csname OCG#2\endcsname\relax + \expandafter\gdef\csname OCG#2\endcsname{#1}% + \global\advance\@ocgp@num by 1 + \ifpdf% PDFLATEX + \immediate\pdfobj{<< /Type /OCG /Name (#1) /Usage <<% + %/Print<</PrintState /ON>> % + %/View<</ViewState /OFF>> % + % /Export<</ExportState /OFF>>% + >> >>}% new ocg + \xdef\@ocgp@curocg{\the\pdflastobj\space 0 R}% reference to current ocg id + \else + \if@ocgp@ifps % soon (not implemented yet) POSTSCRIPT + \xdef\@ocgp@curocg{{@ocg\the\@ocgp@num}}% reference to current ocg id + \special{ps: mark /_objdef \@ocgp@curocg /type/dict /OBJ pdfmark} + \special{ps: mark \@ocgp@curocg << /Type /OCG /Name (#1) + >> /PUT pdfmark}% new ocg + \else % XELATEX + \xdef\@ocgp@curocg{@ocg\the\@ocgp@num}% reference to current ocg id + \special{pdf:obj \@ocgp@curocg\space <</Type/OCG /Name (#1) /Usage << + %/Print<</PrintState /ON>> % + %/View<</ViewState /OFF>> % + %/Export<</ExportState /OFF>>% + >> >>}% new ocg + \fi + \fi + \expandafter\xdef\csname OCGpdfobj#2\endcsname{\@ocgp@curocg} % for ogcx-package + \xdef\@ocgp@ocglist{\@ocgp@ocglist\space\@ocgp@curocg}% list of all OCGs in "first defined" order + \xdef\@ocgp@ocgorderlist{\@ocgp@ocgorderlist\space\@ocgp@curocg} % all OCGs in "first defined" order + hierarchy + \xdef\@ocgp@ocgmaplist{\@ocgp@ocgmaplist\space/OC#2\space\@ocgp@curocg\space ^^J} % name-to-id mapping + \ifnum#3=1 %on + % no list of all default-on OCGs needed, because of basestate on + \else% + \xdef\@ocgp@ocgofflist{\@ocgp@ocgofflist\space\@ocgp@curocg}% list of all default-off OCGs + \fi% + \else + % layer reopened + \fi +} + + + \AtEndDocument{% + %\message{... \@ocgp@ocgorderlist ...} + \ifpdf % PDFLATEX + \pdfcatalog{% + /OCProperties << + /OCGs [\@ocgp@ocglist] + /D <</BaseState/ON /Order [\@ocgp@ocgorderlist] /OFF [\@ocgp@ocgofflist] /AS [% + <</Event/View /OCGs [\@ocgp@ocglist] /Category[/View]>>% + <</Event/Print /OCGs [\@ocgp@ocglist] /Category[/Print]>>% + <</Event/Export /OCGs [\@ocgp@ocglist] /Category[/Export]>>% + ]>>% + >>% + } + \else + \if@ocgp@ifps % soon (not implemented yet) POSTSCRIPT + %\special{ps: mark {Catalog} << + % /OCProperties << + % /OCGs [\@ocgp@ocglist] + % /D <</BaseState/ON /Order [\@ocgp@ocgorderlist] /OFF [\@ocgp@ocgofflist]>> + % >> + %>> /PUT pdfmark}% + \else % XELATEX + \special{pdf:put @catalog << + /OCProperties << + /OCGs [\@ocgp@ocglist] + /D <</BaseState/ON /Order [\@ocgp@ocgorderlist] /OFF [\@ocgp@ocgofflist] /AS [% + <</Event/View /OCGs [\@ocgp@ocglist] /Category[/View]>>% + <</Event/Print /OCGs [\@ocgp@ocglist] /Category[/Print]>>% + <</Event/Export /OCGs [\@ocgp@ocglist] /Category[/Export]>>% + ]>>% + >>% + >>}% + \fi + \fi + } + +\AtBeginDocument{% + \ifpdf % PDFLATEX + \immediate\pdfobj{<<\@ocgp@ocgmaplist\space>>}% + \xdef\@ocgp@namesobj{\the\pdflastobj\space 0 R}% + % append to pageresources + \begingroup + \edef\x{\endgroup + \pdfpageresources{% + \the\pdfpageresources + /Properties \@ocgp@namesobj% + }% + }% + \x + \else + \if@ocgp@ifps % soon (not implemented yet) POSTSCRIPT + %\AddToShipoutPicture{ + %\special{ps: mark {Resources} << + % /Properties << ^^J% + % \@ocgp@ocgmaplist + %>> + %>> /PUT pdfmark}}% + \else % XELATEX + \AddToShipoutPicture{ + \special{pdf: put @resources << + /Properties << ^^J% + \@ocgp@ocgmaplist + >> + >>}}% + \fi + \fi +} + +% parsing a space-delimited ocgid-list to a space-delimited list of ocg-objects +\makeatletter +\def\@ocgp@parseSpaceSeperatedList#1{ \@ocgp@doparseSpaceSeperatedList#1 \@empty } +\def\@ocgp@doparseSpaceSeperatedList#1 #2{% + \ifcsname OCGpdfobj#1\endcsname + \xdef\@ocgp@ocgobjlist{\@ocgp@ocgobjlist\space\csname OCGpdfobj#1\endcsname} + \fi + \ifx #2\@empty + %\@ocgp@ocgobjlist % only for debugging reasons + \else + \expandafter\@ocgp@doparseSpaceSeperatedList + \fi + #2% +} +\makeatother + +% link to toggle a layer in a document without using the layer toolbar of the viewer +\makeatletter +\long\def\toggleocg#1#2{% + \xdef\@ocgp@ocgobjlist{}% + \@ocgp@parseSpaceSeperatedList{#1} + \leavevmode% + \ifpdf + \pdfstartlink user {% + /Subtype /Link + /A << /S/SetOCGState /State [/Toggle \@ocgp@ocgobjlist] >> + %/A << /Type /Action /S /GoTo /D [1 0 R] >> + /Border [0 0 0]% no border + }% + #2\pdfendlink% + \else + \special{pdf: bann + << /Type /Annot + /Subtype /Link + /Border [0 0 0]% no border + /A <</S/SetOCGState /State [/Toggle \@ocgp@ocgobjlist] >>% + >>}#2% + \special{pdf:eann}% + \fi +} +\makeatother |