|
|
878a2b |
#!/bin/bash
|
|
|
878a2b |
#
|
|
|
878a2b |
# docbook_convertToPdfFromSgml.sh -- This function transforms DocBook
|
|
|
878a2b |
# files which have set the SGML DTD in them. To produce PDF from
|
|
|
878a2b |
# DocBook SGML DTD, we take the DocBook XML DTD file and change its
|
|
|
878a2b |
# DTD from XML to SGML. Since XML is SGML shoudn't be any problem.
|
|
|
878a2b |
# Once the DTD has been changed from XML to SGML, we use openjade
|
|
|
878a2b |
# (through `jw' shell script) to convert the SGML-based DocBook file
|
|
|
878a2b |
# to PDF. Customization can be achieved through DSL
|
|
|
878a2b |
# (docbook-style-dsssl-1.79-4.1) shipped in this distribution.
|
|
|
878a2b |
#
|
|
|
878a2b |
# In this configuration and using default configuration settings, I've
|
|
|
878a2b |
# presented the following problems:
|
|
|
878a2b |
#
|
|
|
878a2b |
# 1. It is not possible to produce localized PDF outputs through
|
|
|
878a2b |
# `xml2po', the default way of producing localized content inside
|
|
|
878a2b |
# `centos-art.sh' script.
|
|
|
878a2b |
#
|
|
|
878a2b |
# In this configuration and using default configuration settins, I've
|
|
|
878a2b |
# presented the following advantages:
|
|
|
878a2b |
#
|
|
|
878a2b |
# 1. The PDF output produced from SGML-based files seem to be better
|
|
|
878a2b |
# looking an less buggy than PDF output produced from XML-based
|
|
|
878a2b |
# files, visually I mean.
|
|
|
878a2b |
#
|
|
|
878a2b |
# To make the whole process transparent, a temporal directory is
|
|
|
878a2b |
# created for intermediate works and final files are moved then to
|
|
|
878a2b |
# their final location.
|
|
|
878a2b |
#
|
|
|
878a2b |
# Copyright (C) 2009, 2010, 2011 The CentOS Project
|
|
|
878a2b |
#
|
|
|
878a2b |
# This program is free software; you can redistribute it and/or modify
|
|
|
878a2b |
# it under the terms of the GNU General Public License as published by
|
|
|
878a2b |
# the Free Software Foundation; either version 2 of the License, or (at
|
|
|
878a2b |
# your option) any later version.
|
|
|
878a2b |
#
|
|
|
878a2b |
# This program is distributed in the hope that it will be useful, but
|
|
|
878a2b |
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
878a2b |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
878a2b |
# General Public License for more details.
|
|
|
878a2b |
#
|
|
|
878a2b |
# You should have received a copy of the GNU General Public License
|
|
|
878a2b |
# along with this program; if not, write to the Free Software
|
|
|
878a2b |
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
878a2b |
#
|
|
|
878a2b |
# ----------------------------------------------------------------------
|
|
|
878a2b |
# $Id$
|
|
|
878a2b |
# ----------------------------------------------------------------------
|
|
|
878a2b |
|
|
|
878a2b |
function docbook_convertToPdfFromSgml {
|
|
|
878a2b |
|
|
|
878a2b |
# Print action message.
|
|
|
878a2b |
if [[ -f ${FILE}.sgml.pdf ]];then
|
|
|
878a2b |
cli_printMessage "${FILE}.sgml.pdf" --as-updating-line
|
|
|
878a2b |
else
|
|
|
878a2b |
cli_printMessage "${FILE}.sgml.pdf" --as-creating-line
|
|
|
878a2b |
fi
|
|
|
878a2b |
|
|
|
878a2b |
local -a STYLE_TEMPLATE
|
|
|
878a2b |
local -a STYLE_INSTANCE
|
|
|
878a2b |
local STYLE_INSTANCE_FINAL=''
|
|
|
878a2b |
|
|
|
878a2b |
# Define name of temporal directory where the DocBook to PDF
|
|
|
878a2b |
# transformation will take place.
|
|
|
878a2b |
local TMPDIR=$(cli_getTemporalFile "docbook2pdf")
|
|
|
878a2b |
|
|
|
878a2b |
# Define absolute path to DocBook source file. This is the
|
|
|
878a2b |
# repository documentation manual file where DOCTYPE and ENTITY
|
|
|
878a2b |
# definition lines are set.
|
|
|
878a2b |
local SRC=${INSTANCE}
|
|
|
878a2b |
|
|
|
878a2b |
# Define absolute path to PDF target file. This is the final
|
|
|
878a2b |
# location the PDF file produced as result of DocBook to PDF
|
|
|
878a2b |
# transformation will be stored in.
|
|
|
878a2b |
local DST="${FILE}.sgml.pdf"
|
|
|
878a2b |
|
|
|
878a2b |
# Define file name of PDF file. This is the file we were looking
|
|
|
878a2b |
# for and the one moved, once produced.
|
|
|
878a2b |
local PDF=$(basename ${SRC} | sed -r 's!\.docbook$!.pdf!')
|
|
|
878a2b |
|
|
|
878a2b |
# Replace document definition from XML to SGML.
|
|
|
878a2b |
sed -i -r \
|
|
|
878a2b |
-e 's!"-//OASIS//DTD DocBook XML!"-//OASIS//DTD DocBook!' \
|
|
|
878a2b |
-e 's!"http://www\.oasis-open\.org/docbook/xml/([[:digit:]])\.([[:digit:]])/docbookx\.dtd"!"docbook/sgml-dtd-\1.\2-1.0-30.1/docbook.dtd"!' \
|
|
|
878a2b |
$SRC
|
|
|
878a2b |
|
|
|
878a2b |
# Prepare style final instance used in transformations.
|
|
|
878a2b |
docbook_prepareStyles "${DOCBOOK_STYLES_DIR}/docbook2pdf.dsl"
|
|
|
878a2b |
|
|
|
878a2b |
# Verify temporal directory and create it if doesn't exist.
|
|
|
878a2b |
if [[ ! -d $TMPDIR ]];then
|
|
|
878a2b |
mkdir $TMPDIR
|
|
|
878a2b |
fi
|
|
|
878a2b |
|
|
|
878a2b |
# Move inside temporal directory.
|
|
|
878a2b |
pushd $TMPDIR > /dev/null
|
|
|
878a2b |
|
|
|
878a2b |
# Create PDF format.
|
|
|
878a2b |
docbook2pdf --dsl ${STYLE_INSTANCE_FINAL} ${SRC} &> /dev/null
|
|
|
878a2b |
|
|
|
878a2b |
# Verify `docbook2pdf' exit status and, if everything is ok, move
|
|
|
878a2b |
# PDF file from temporal directory to its target location.
|
|
|
878a2b |
if [[ $? -eq 0 ]];then
|
|
|
878a2b |
mv $PDF $DST
|
|
|
878a2b |
else
|
|
|
878a2b |
cli_printMessage "`gettext "Cannot produce the PDF file."`" --as-error-line
|
|
|
878a2b |
fi
|
|
|
878a2b |
|
|
|
878a2b |
# Return to where we initially were.
|
|
|
878a2b |
popd > /dev/null
|
|
|
878a2b |
|
|
|
878a2b |
# Remove temporal directory and temporal style instances created.
|
|
|
878a2b |
rm -r $TMPDIR
|
|
|
878a2b |
rm ${STYLE_INSTANCE[*]}
|
|
|
878a2b |
|
|
|
878a2b |
}
|