Fill properly tiles on export

This commit is contained in:
Pierre HUBERT 2023-08-23 16:07:21 +02:00
parent 26dceaba06
commit 17a2cd156d
2 changed files with 24 additions and 0 deletions

View File

@ -0,0 +1,8 @@
export function getAllIndexes(s: string, val: string) {
var indexes = [],
i = -1;
while ((i = s.indexOf(val, i + 1)) !== -1) {
indexes.push(i);
}
return indexes;
}

View File

@ -9,6 +9,7 @@ import { IconButton } from "@mui/material";
import PictureAsPdfIcon from "@mui/icons-material/PictureAsPdf";
import { jsPDF } from "jspdf";
import "svg2pdf.js";
import { getAllIndexes } from "../../utils/string_utils";
export function ComplexFamilyTree(p: {
tree: FamilyTreeNode;
@ -112,6 +113,21 @@ export function ComplexFamilyTree(p: {
dstSVG = dstSVG.replaceAll(`>UNKNOWN<`, `fill="#000">INCONNU<`);
let womanTiles = getAllIndexes(dstSVG, "card-female");
for (const i of womanTiles) {
dstSVG =
dstSVG.substring(0, i) +
dstSVG.substring(i + 1).replace(`fill="white"`, `fill="#ffb6c1"`);
}
let manTiles = getAllIndexes(dstSVG, "card-male");
for (const i of manTiles) {
dstSVG =
dstSVG.substring(0, i) +
dstSVG.substring(i + 1).replace(`fill="white"`, `fill="#add8e6"`);
}
//navigator.clipboard.writeText(dstSVG);
target.innerHTML = dstSVG;
await doc.svg(target, {