office-gobmx/bin/replace_missing_fonts.sh

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

81 lines
2.8 KiB
Bash
Raw Normal View History

#!/bin/bash
declare -A replacements
replacements["Agency FB"]="Noto Sans"
replacements["Segoe UI"]="Noto Sans"
replacements["Univers 45 Light"]="Noto Sans"
replacements["Trebuchet MS"]="Noto Sans"
replacements["Perpetua"]="Noto Sans"
replacements["Calibri Light"]="Noto Sans"
replacements["Rockwell"]="Noto Sans"
replacements["DFKai-SB"]="Noto Sans"
replacements["Gill Sans MT"]="Noto Sans"
replacements["BentonSans Medium"]="Noto Sans"
replacements["BentonSans"]="Noto Sans"
replacements["AdvPS88D1"]="Noto Sans"
replacements["NexusSansOT"]="Noto Sans"
replacements["Segoe Script"]="Noto Sans"
CppunitTest_sw_ooxmlexport6: turn on set_non_application_font_use From bin/replace_missing_fonts.sh: Replacing 'Kings Caslon Text' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data/TestVMLData.docx Replacing 'Impact' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data/fdo74110.docx Replacing 'Century Gothic' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data/gradient-fill-preservation.docx Replacing 'Kings Caslon Text' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data/image_data.docx Replacing 'Segoe UI' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data/tdf119054.docx Replacing 'DINPro-Medium' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data/tdf128752.docx Replacing 'Open Sans Light' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data/tdf153891.docx Replacing 'Lora - regular' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data/tdf153891.docx Replacing 'Century Gothic' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data/tdf153891.docx Replacing 'Segoe UI' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data/tdf153891.docx Replacing 'Times' with 'Liberation Serif' in sw/qa/extras/ooxmlexport/data/tdf93676-1.odt Replacing 'FreeSans' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data/tdf93676-1.odt Replacing 'Times' with 'Liberation Serif' in sw/qa/extras/ooxmlexport/data/testOuterShdw.docx Replacing 'Jokerman' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data/testOuterShdw.docx Replacing 'Century Gothic' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data/testOuterShdw.docx Replacing 'Calibri Light' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data//tdf119054.docx Replacing 'Calibri Light' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data//tdf132514.docx Also remove some replacements in replace_missing_fonts.sh which are not needed Change-Id: Ife0e4a6852907e658b2f2ed42c91b26b5eb06572 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164536 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
2024-03-07 06:50:31 -06:00
replacements["Impact"]="Noto Sans"
replacements["Century Gothic"]="Noto Sans"
replacements["Kings Caslon Text"]="Noto Sans"
replacements["Times"]="Liberation Serif"
replacements["Jokerman"]="Noto Sans"
replacements["FreeSans"]="Noto Sans"
replacements["DINPro-Medium"]="Noto Sans"
replacements["Open Sans Light"]="Noto Sans"
replacements["Lora - regular"]="Noto Sans"
CppunitTest_sw_ooxmlexport5: turn on set_non_application_font_use From bin/replace_missing_fonts.sh: Replacing 'Tahoma' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data//fdo77887.docx Replacing 'Thorndale' with 'Liberation Serif' in sw/qa/extras/ooxmlexport/data//ooo96040-2.odt Replacing 'Tahoma' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data//ooo96040-2.odt Replacing 'Albany' with 'Liberation Sans' in sw/qa/extras/ooxmlexport/data//ooo96040-2.odt Replacing 'Trebuchet MS' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data//fdo77727.docx Replacing 'Times' with 'Liberation Serif' in sw/qa/extras/ooxmlexport/data//fdo77727.docx Replacing 'Tahoma' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data//fdo77727.docx Replacing 'Century Gothic' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data//fdo77727.docx Replacing 'Lucida Sans Unicode' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data//fdo77727.docx Replacing 'Candara' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data//fdo77727.docx Replacing 'Tahoma' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data//fdo78420.docx Replacing 'Verdana' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data//fdo78420.docx Replacing 'Gill Sans MT' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data//fdo79822.docx Replacing 'Tahoma' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data//fdo79822.docx Change-Id: I298d9007ae6bd59a8a804902524b59ac524618c9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164548 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
2024-03-07 11:52:48 -06:00
replacements["Tahoma"]="Noto Sans"
replacements["Thorndale"]="Liberation Serif"
replacements["Albany"]="Liberation Sans"
replacements["Lucida Sans Unicode"]="Noto Sans"
replacements["Candara"]="Noto Sans"
replacements["Verdana"]="Noto Sans"
replacements["Gill Sans MT"]="Noto Sans"
extracted_folder=".temp_extracted"
for file in $(find "$1" -type f); do
file_name=$(basename "$file")
current_extension="${file_name##*.}"
CppunitTest_sw_ooxmlexport6: turn on set_non_application_font_use From bin/replace_missing_fonts.sh: Replacing 'Kings Caslon Text' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data/TestVMLData.docx Replacing 'Impact' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data/fdo74110.docx Replacing 'Century Gothic' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data/gradient-fill-preservation.docx Replacing 'Kings Caslon Text' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data/image_data.docx Replacing 'Segoe UI' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data/tdf119054.docx Replacing 'DINPro-Medium' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data/tdf128752.docx Replacing 'Open Sans Light' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data/tdf153891.docx Replacing 'Lora - regular' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data/tdf153891.docx Replacing 'Century Gothic' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data/tdf153891.docx Replacing 'Segoe UI' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data/tdf153891.docx Replacing 'Times' with 'Liberation Serif' in sw/qa/extras/ooxmlexport/data/tdf93676-1.odt Replacing 'FreeSans' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data/tdf93676-1.odt Replacing 'Times' with 'Liberation Serif' in sw/qa/extras/ooxmlexport/data/testOuterShdw.docx Replacing 'Jokerman' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data/testOuterShdw.docx Replacing 'Century Gothic' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data/testOuterShdw.docx Replacing 'Calibri Light' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data//tdf119054.docx Replacing 'Calibri Light' with 'Noto Sans' in sw/qa/extras/ooxmlexport/data//tdf132514.docx Also remove some replacements in replace_missing_fonts.sh which are not needed Change-Id: Ife0e4a6852907e658b2f2ed42c91b26b5eb06572 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164536 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
2024-03-07 06:50:31 -06:00
if [[ $current_extension == "docx" || $current_extension == "xlsx" || $current_extension == "pptx" || $current_extension == "odt" ]]; then
base_name="${file_name%.*}"
# move the file to a new .zip file
cp "$file" "${base_name}.zip"
# extract the zip file to a temporary folder
unzip -qq ./"${base_name}.zip" -d "$extracted_folder" > /dev/null
for key in "${!replacements[@]}"
do
file_changed=false
value=${replacements[$key]}
for subfile in $(find "$extracted_folder" -type f); do
# Replace only if it's between quotes
if grep -q "\"$key\"" "$subfile"; then
sed -i "s/\"$key\"/\"$value\"/g" "$subfile"
file_changed=true
# or between '&quot;'
elif grep -q "&quot;$key&quot;" "$subfile"; then
sed -i "s/&quot;$key&quot;/\&quot;$value\&quot;/g" "$subfile"
file_changed=true
fi
done
if [ "$file_changed" = true ]; then
# Create a new zip file with the modified files
cd "$extracted_folder"; zip -r ../"${base_name}.zip" . > /dev/null; cd ..
mv "${base_name}.zip" "$file"
echo "Replacing '$key' with '$value' in $file"
fi
done
# Clean up the temporary extracted folder
rm -rf "$extracted_folder"
fi
done