Hi, Michael.

Thanks for the reply. I am not looking to edit source files in OpenOffice. I
want to link their content, like linking an image, except linking to a text
file. I have since created a script, as follows:

#!/bin/bash

FILENAME=$1
BASENAME=${FILENAME%%.*}

enscript --pretty-print=sql -f Courier12 -X ps -B -1 --highlight=sql \
  $2 -h -o - $FILENAME | \
  gs -dSAFER -sDEVICE=png16m -dGraphicsAlphaBits=4 -r300 \
  -sOutputFile=$BASENAME.png -dNOPAUSE > /dev/null && \
  convert -trim $BASENAME.png $BASENAME-trimmed.png && \
  mv $BASENAME-trimmed.png $BASENAME.png

This script takes a text file, applies some syntax highlighting, then writes
the result to an image at 300 dpi. The text file can be SQL code, Java
source, R commands, Python script, you name it. For what it's worth, I've
been editing text files with vi for over 15 years. ;-)

The result is this: http://i.imgur.com/v8yCy.png

However, it is an extra step (I have to run the script after editing the
source code to generate a new image) and if the size of the image changes,
OpenOffice doesn't stretch the enclosing frame. This means that if I change
the source code (by adding or removing lines), I have to re-import the
image.

So in my ideal world, the frame would simply include the text and an
OpenOffice add-on (such as CodeFormatter or other) would apply the syntax
highlighting.

These are more difficult. IIUC the above text editing programs use a
> collection of RegEx'es to achieve the highlighting. The only way i know how
>

Only simpler languages can get away with RegEx for syntax highlighting.
Complex languages like C++ require other mechanisms.


> to do this would be to print screen in a text editor and trim the image
> then
> add a caption to the subsequent image. This would render the text useless
>

Not only that, but it would not get 300 dpi. Screen resolutions are 72 dpi,
so I would have to scale the image. This can be done (i.e., set the size to
300% and then set the dpi to 288), but the text isn't quite as beautiful as
it can be.


> In OpenOffice.org to achieve suitable coloured syntax output would require
> you
> to write the appropriate macro, adding all relevant RegEx'es as you go. I
> doubt this would already exist in an extension.
>

Two extensions exist for this:

http://extensions.services.openoffice.org/en/project/CodeFormatter
http://extensions.services.openoffice.org/en/project/coooder

The linking text, however, is the bigger issue. Essentially, I don't want to
have to change both the source code as it resides in a source file *and* the
same source code inside OpenOffice. I want to change the source code *once*
and have OpenOffice import those changes.

It probably won't be a big deal when I move the content over to Scribus.

Thanks for all the help!
Dave

Reply via email to