summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXisco Fauli <xiscofauli@libreoffice.org>2024-03-04 17:55:52 +0100
committerXisco Fauli <xiscofauli@libreoffice.org>2024-03-05 09:33:05 +0100
commit4a3412a34a15e5f5653329da8f073f013ca0c9dc (patch)
treed002cc8ad27b8f86cf608aeaba389e55e1bd86e6
parentfbefbfc357aaf4e36a10085b6645e8ba97187543 (diff)
bin: Add initial script to replace missing fonts
It already contains some replacements I found along the way For now it works with docx, xlsx and pptx files. I have to test it with odf formats. Change-Id: Ia68bc7561f0e41580ad1834a1a345b618f3e688c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164393 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
-rwxr-xr-xbin/replace_string_in_zip.sh68
1 files changed, 68 insertions, 0 deletions
diff --git a/bin/replace_string_in_zip.sh b/bin/replace_string_in_zip.sh
new file mode 100755
index 000000000000..184f37835bc7
--- /dev/null
+++ b/bin/replace_string_in_zip.sh
@@ -0,0 +1,68 @@
+#!/bin/bash
+
+declare -A replacements
+replacements["Agency FB"]="Noto Sans"
+replacements["Noto Sans Light"]="Noto Sans"
+replacements["Segoe UI"]="Noto Sans"
+replacements["Univers 45 Light"]="Noto Sans"
+replacements["Trebuchet MS"]="Noto Sans"
+replacements["Georgia"]="Noto Serif"
+replacements["Perpetua"]="Noto Sans"
+replacements["Garamond"]="Noto Serif"
+replacements["Calibri Light"]="Noto Sans"
+replacements["Consolas"]="DejaVu Sans Mono"
+replacements["Verdana"]="Noto Sans"
+replacements["Rockwell"]="Noto Sans"
+replacements["Tms Rmn"]="DejaVu Sans"
+replacements["Tahoma"]="Noto Sans"
+replacements["DFKai-SB"]="Noto Sans"
+replacements["Gill Sans MT"]="Noto Sans"
+replacements["Helvetica"]="Liberation Sans"
+replacements["Liberation Serif"]="DejaVu Sans"
+replacements["BentonSans Medium"]="Noto Sans"
+replacements["BentonSans"]="Noto Sans"
+replacements["AdvPS88D1"]="Noto Sans"
+replacements["NexusSansOT"]="Noto Sans"
+
+extracted_folder=".temp_extracted"
+
+for file in $(find "$1" -type f); do
+ file_name=$(basename "$file")
+ current_extension="${file_name##*.}"
+
+ if [[ $current_extension == "docx" || $current_extension == "xlsx" || $current_extension == "pptx" ]]; 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
+ if grep -q "$key" "$subfile"; then
+ # use sed to replace the string in the file if it exists
+ sed -i "s/$key/$value/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
+