Blame Scripts/Bash/Functions/Render/Docbook/docbook_convertToPdfFromXml.sh

878a2b
#!/bin/bash
878a2b
#
878a2b
# docbook_convertToPdfFromXml.sh -- This function transforms DocBook
878a2b
# files which have set the XML DTD in them.  To produce PDF from
878a2b
# DocBook XML DTD, we need an XSLT engine (e.g., through `xsltproc'
878a2b
# command) to produce formatting objects (FO), which then must be
878a2b
# processed with an FO engine (e.g., through `pdfxmltex' command,
878a2b
# which uses PassiveTex) to produce the PDF output.
878a2b
#
878a2b
# In this configuration and using default configuration settings, I've
878a2b
# presented the following problems:
878a2b
#
878a2b
# 1. Something is wrong with headings. They are not expanded along
878a2b
# the whole page-body. They seem to be rendered in a reduced width
878a2b
# (1 inch approximatly). This provokes the heading to be broken in a
878a2b
# two-to-five letters column and sometimes it overlaps the
878a2b
# sectioning titles (e.g., chatper, section). I tried to customize
878a2b
# the value of `header.column.widths' and `page.margin.top' but it
878a2b
# seems to be not there where I need to touch.
878a2b
#
878a2b
# 2. TOC's indentation is not rendered. Even the `toc.indent.width'
878a2b
# property is set to 24 by default.
878a2b
#
878a2b
# 3. Inside lists, when items are more than one line, the
878a2b
# indentation seems to work for the first line only.  All other
878a2b
# lines in the same item are not indented and begin completly
878a2b
# unaligned.
878a2b
#
878a2b
# 4. Long file paths near the end of page-body aren't hyphenated.
878a2b
# Even the `hyphenate' property is set to `true' by default.
878a2b
#
878a2b
# In this configuration and using default configuration settings, I've
878a2b
# presented the following advantages:
878a2b
#
878a2b
# 1. It is possible to produce localized PDF outputs through
878a2b
# `xml2po', the default way of producing localized content inside
878a2b
# the `centos-art.sh' script.
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
#
03486a
# Copyright (C) 2009, 2010, 2011, 2012 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_convertToPdfFromXml {
878a2b
878a2b
    # Print action message.
054a5f
    cli_printMessage "${FILE}.pdf" --as-creating-line
878a2b
878a2b
    local -a STYLE_TEMPLATE
878a2b
    local -a STYLE_INSTANCE
878a2b
    local STYLE_INSTANCE_FINAL=''
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.
054a5f
    local DST="${FILE}.pdf"
878a2b
878a2b
    # Define file name of formatting object (.fo) file. This file is
878a2b
    # an intermediate file needed to produced the PDF.
054a5f
    local FO=$(echo ${INSTANCE} | sed -r 's/docbook$/fo/g')
878a2b
878a2b
    # Define file name of PDF file.  This is the file we were looking
878a2b
    # for and the one moved, once produced.
054a5f
    local PDF=$(echo ${INSTANCE} | sed -r 's/docbook$/pdf/g')
878a2b
878a2b
    # Prepare XSL final instances used in transformations.
054a5f
    docbook_prepareStyles "${DOCBOOK_XSL_DIR}/docbook2fo.xsl"
878a2b
054a5f
    # Create link to `Images' directory. This is the directory where
054a5f
    # images used by documentation are stored in.
054a5f
    ln -s ${TCAR_WORKDIR}/trunk/Identity/Images/Webenv $(dirname ${INSTANCE})/Images
878a2b
878a2b
    # Create formatting object supressing output from stderr.
9b787f
    xsltproc --output ${FO} ${STYLE_INSTANCE_FINAL} ${SRC} 2> /dev/null
878a2b
054a5f
    # Create PDF format from formatting object. Because we are using
054a5f
    # relative path to access `Images', it is necessary to move the
054a5f
    # directory stack into the temporal directory where instance files
054a5f
    # are created. Otherwise, the location used to load images will
054a5f
    # fail.
878a2b
    if [[ $? -eq 0 ]];then
054a5f
        pushd $(dirname ${INSTANCE}) > /dev/null
054a5f
        xmlto -o $(dirname ${FILE}) pdf ${FO}
054a5f
        popd > /dev/null
878a2b
    else 
878a2b
        cli_printMessage "`gettext "Cannot produce the PDF file."`" --as-error-line
878a2b
    fi
878a2b
878a2b
}