mirror of
https://github.com/felipegcoutinho/openmonetis.git
synced 2026-05-09 02:51:46 +00:00
refactor(exports): renderizar logos SVG em alta resolução no PDF
Atualiza loadExportLogoDataUrl para carregar SVGs e rasterizar no canvas a 4× a resolução natural antes de retornar o data URL — preserva nitidez quando o PDF amplia a imagem. Default do path mudou para /images/logo_text.svg. Os exports de categorias e lançamentos agora apontam para os arquivos .svg em vez dos .png removidos. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -224,8 +224,8 @@ export function CategoryReportExport({
|
||||
const doc = new jsPDF({ orientation: "landscape" });
|
||||
const primaryColor = getPrimaryPdfColor();
|
||||
const [smallLogoDataUrl, textLogoDataUrl] = await Promise.all([
|
||||
loadExportLogoDataUrl("/images/logo_small.png"),
|
||||
loadExportLogoDataUrl("/images/logo_text.png"),
|
||||
loadExportLogoDataUrl("/images/logo_small.svg"),
|
||||
loadExportLogoDataUrl("/images/logo_text.svg"),
|
||||
]);
|
||||
let brandingEndX = 14;
|
||||
|
||||
|
||||
@@ -229,8 +229,8 @@ export function TransactionsExport({
|
||||
const doc = new jsPDF({ orientation: "landscape" });
|
||||
const primaryColor = getPrimaryPdfColor();
|
||||
const [smallLogoDataUrl, textLogoDataUrl] = await Promise.all([
|
||||
loadExportLogoDataUrl("/images/logo_small.png"),
|
||||
loadExportLogoDataUrl("/images/logo_text.png"),
|
||||
loadExportLogoDataUrl("/images/logo_small.svg"),
|
||||
loadExportLogoDataUrl("/images/logo_text.svg"),
|
||||
]);
|
||||
let brandingEndX = 14;
|
||||
|
||||
|
||||
@@ -65,8 +65,10 @@ export function getPrimaryPdfColor(): [number, number, number] {
|
||||
return FALLBACK_PRIMARY_COLOR;
|
||||
}
|
||||
|
||||
const EXPORT_LOGO_RENDER_SCALE = 4;
|
||||
|
||||
export async function loadExportLogoDataUrl(
|
||||
logoPath = "/images/logo_text.png",
|
||||
logoPath = "/images/logo_text.svg",
|
||||
): Promise<string | null> {
|
||||
if (typeof window === "undefined" || typeof document === "undefined") {
|
||||
return null;
|
||||
@@ -77,13 +79,16 @@ export async function loadExportLogoDataUrl(
|
||||
image.crossOrigin = "anonymous";
|
||||
|
||||
image.onload = () => {
|
||||
const width = image.naturalWidth || image.width;
|
||||
const height = image.naturalHeight || image.height;
|
||||
if (!width || !height) {
|
||||
const naturalWidth = image.naturalWidth || image.width;
|
||||
const naturalHeight = image.naturalHeight || image.height;
|
||||
if (!naturalWidth || !naturalHeight) {
|
||||
resolve(null);
|
||||
return;
|
||||
}
|
||||
|
||||
const width = Math.round(naturalWidth * EXPORT_LOGO_RENDER_SCALE);
|
||||
const height = Math.round(naturalHeight * EXPORT_LOGO_RENDER_SCALE);
|
||||
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.width = width;
|
||||
canvas.height = height;
|
||||
|
||||
Reference in New Issue
Block a user