Translate English to Hieroglyphs
Hieroglyphic Output:
Hieroglyphs will appear here.
Transliteration:
-
Hieroglyph Guide
Common Uniliteral Signs (Alphabet)
Common Words & Symbols
${key}
Meaning: ${word.meaning}
Translit: ${word.translit}
`; commonWordsGuideDiv.appendChild(itemDiv); } } async function aeh_downloadPdf() { const { jsPDF } = window.jspdf; const doc = new jsPDF(); const appContainer = document.getElementById('hieroglyphsTranslatorApp'); // Theme colors for PDF const titleColor = '#003366'; // Nile Blue const textColor = '#3A2A18'; // Dark Brown const highlightColor = '#D4AF37'; // Gold-like let yPos = 20; doc.setFont('helvetica', 'bold'); doc.setTextColor(titleColor); doc.setFontSize(16); doc.text("Ancient Egyptian Hieroglyphs Output", 14, yPos); yPos += 10; doc.setFont('helvetica', 'normal'); doc.setTextColor(textColor); doc.setFontSize(12); const englishInput = document.getElementById('englishInput').value; doc.text("Original English Input:", 14, yPos); yPos += 7; doc.setFont('helvetica', 'italic'); doc.text(englishInput || "No input provided.", 14, yPos, { maxWidth: 180 }); yPos += Math.ceil(doc.getTextDimensions(englishInput || "No input provided.", { maxWidth: 180 }).h) + 7; doc.setFont('helvetica', 'normal'); doc.setTextColor(textColor); const transliteration = document.getElementById('transliterationOutput').textContent; doc.text("Transliteration:", 14, yPos); yPos += 7; doc.setFont('helvetica', 'italic'); doc.text(transliteration || "-", 14, yPos, { maxWidth: 180 }); yPos += Math.ceil(doc.getTextDimensions(transliteration || "-", { maxWidth: 180 }).h) + 10; doc.setFont('helvetica', 'normal'); doc.setTextColor(textColor); doc.text("Hieroglyphic Representation:", 14, yPos); yPos += 7; const hieroglyphOutputDiv = document.getElementById('hieroglyphOutput'); if (hieroglyphOutputDiv.children.length > 0 && hieroglyphOutputDiv.textContent.trim() !== "Hieroglyphs will appear here." && hieroglyphOutputDiv.textContent.trim() !== "Could not generate hieroglyphs for this input.") { try { // Ensure SVGs are fully rendered and styles applied before capturing await new Promise(resolve => setTimeout(resolve, 100)); // Small delay const canvas = await html2canvas(hieroglyphOutputDiv, { scale: 2, // Increase scale for better quality backgroundColor: '#FFFFFF', // Set explicit background useCORS: true, // If SVGs were external, not an issue here onclone: (clonedDoc) => { // Ensure styles are correctly applied in cloned document for rendering const clonedOutputDiv = clonedDoc.getElementById('hieroglyphOutput'); if (clonedOutputDiv) { clonedOutputDiv.style.backgroundColor = '#FFFFFF'; // White background for capture const svgs = clonedOutputDiv.querySelectorAll('svg'); svgs.forEach(svg => { svg.style.fill = '#3A2A18'; // Ensure fill color for SVGs }); } } }); const imgData = canvas.toDataURL('image/png'); const imgProps = doc.getImageProperties(imgData); const pdfWidth = doc.internal.pageSize.getWidth() - 28; // Page width - margins const imgHeight = (imgProps.height * pdfWidth) / imgProps.width; if (yPos + imgHeight > doc.internal.pageSize.getHeight() - 20) { // Check if it fits doc.addPage(); yPos = 20; } doc.addImage(imgData, 'PNG', 14, yPos, pdfWidth, imgHeight); yPos += imgHeight + 10; } catch (error) { console.error("Error generating PDF image:", error); doc.text("Error rendering hieroglyphs in PDF.", 14, yPos); yPos += 10; } } else { doc.text("No hieroglyphs were generated or input was invalid.", 14, yPos); yPos += 10; } doc.save("egyptian_hieroglyphs_output.pdf"); } document.addEventListener('DOMContentLoaded', function() { const firstTabButton = document.querySelector("#hieroglyphsTranslatorApp .aeh-tab-button"); if (firstTabButton) { const initialEvent = { currentTarget: firstTabButton }; aeh_openTab(initialEvent, 'englishToHieroglyphsTab'); } aeh_populateGuide(); document.getElementById('englishInput').addEventListener('keypress', function(e) { if (e.key === 'Enter' && !e.shiftKey) { // Allow shift+enter for new line e.preventDefault(); aeh_processEnglishInput(); } }); });