Created
November 28, 2014 05:09
-
-
Save nogajun/f4313f32c07511ce1d83 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Convert HUE/360 Palette to LibreOffice Color Palette. | |
# Usage: hue3602soc.sh [ HUE360_palette.txt ] | |
# | |
# input file structure | |
# color name: #(color code) | |
# | |
# input file example: | |
# white: #ffffff | |
# black: #000000 | |
# | |
# Copyright: Jun NOGATA <nogajun@gmail.com> | |
# | |
# This program is free software; you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation; either version 2 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program; if not, write to the Free Software | |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
# MA 02110-1301, USA. | |
HUE_FILE="$1" | |
usage(){ | |
echo "Usage: hue3602soc.sh [ HUE360_palette.txt ]" | |
echo "Convert HUE/360 Palette(.txt) to LibreOffice Color Palette(.soc)." | |
echo | |
} | |
# file Check | |
if [ "$#" = "0" ]; then | |
usage | |
exit 1 | |
fi | |
if [ ! -e "$1" ]; then | |
echo "Can't file reading: No such file or directory" | |
exit 1 | |
fi | |
FILENAME="${HUE_FILE%.txt}.soc" | |
# ------------------------------------------------------------------------ | |
put_header(){ | |
# put header | |
cat << EOL > ${FILENAME} | |
<?xml version="1.0" encoding="UTF-8"?> | |
<ooo:color-table xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ooo="http://openoffice.org/2004/office"> | |
<!-- White to Black --> | |
<draw:color draw:name="White" draw:color="#FFFFFF"/> | |
<draw:color draw:name="Gray1" draw:color="#E3E3E3"/> | |
<draw:color draw:name="Gray2" draw:color="#C6C6C6"/> | |
<draw:color draw:name="Gray3" draw:color="#AAAAAA"/> | |
<draw:color draw:name="Gray4" draw:color="#8E8E8E"/> | |
<draw:color draw:name="Gray5" draw:color="#717171"/> | |
<draw:color draw:name="Gray6" draw:color="#555555"/> | |
<draw:color draw:name="Gray7" draw:color="#393939"/> | |
<draw:color draw:name="Gray8" draw:color="#1C1C1C"/> | |
<draw:color draw:name="Black" draw:color="#000000"/> | |
<!-- Convert Palette --> | |
EOL | |
} | |
put_footer(){ | |
# put footer | |
echo "</ooo:color-table>" >> ${FILENAME} | |
} | |
put_header | |
COUNT=1 | |
cat ${HUE_FILE} | while read; do | |
if [ "${REPLY}" != "" ] || [ ! "$(echo ${REPLY}|grep ^#)" ] ; then | |
C=(${REPLY}) | |
COLORNAME="${C[0]%:}" | |
COLORCODE="${C[1]}" | |
if [ "${COLORNAME}" = "subColor" ]; then | |
COLORNAME="${COLORNAME}${COUNT}" | |
COUNT=$((${COUNT}+1)) | |
fi | |
echo " <draw:color draw:name=\"${COLORNAME}\" draw:color=\"${COLORCODE}\"/>" >> ${FILENAME} | |
fi | |
done | |
put_footer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment