Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#857 Update link and icon on export #882

Merged
merged 1 commit into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions public/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 21 additions & 12 deletions src/util/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { languageToFontsCss } from '../components/svgs/nodes/text';
import { EdgeAttributes, GraphAttributes, NodeAttributes, NodeType } from '../constants/constants';
import { MiscNodeType } from '../constants/nodes';
import { StationType } from '../constants/stations';
import i18n from '../i18n/config';
import { FONTS_CSS, makeBase64EncodedFontsStyle } from './fonts';
import { findNodesExist } from './graph';
import { calculateCanvasSize } from './helpers';
Expand Down Expand Up @@ -46,7 +47,7 @@ export const makeRenderReadySVGElement = async (

const elem = document.getElementById('canvas')!.cloneNode(true) as SVGSVGElement;
// append rmp info if user does not want to share rmp info
if (!generateRMPInfo) elem.appendChild(generateRmpInfo(xMax - 400, yMax - 120));
if (!generateRMPInfo) elem.appendChild(await generateRmpInfo(xMax - 400, yMax - 120));
// reset svg viewBox to display all the nodes in the graph
// otherwise the later drawImage won't be able to show all of them
elem.setAttribute('viewBox', `${xMin} ${yMin} ${width} ${height}`);
Expand Down Expand Up @@ -228,29 +229,37 @@ const loadFacilitiesSvg = async (
}
};

const generateRmpInfo = (x: number, y: number) => {
const generateRmpInfo = async (x: number, y: number) => {
const info = document.createElementNS('http://www.w3.org/2000/svg', 'g');
info.setAttribute('transform', `translate(${x}, ${y})scale(2)`);

const logo = document.createElementNS('http://www.w3.org/2000/svg', 'image');
// FIXME: return after image is loaded
// logo.setAttribute('href', 'https://uat-railmapgen.github.io/rmp/logo192.png');
// logo.setAttribute('href', logoImg);
logo.setAttribute('width', '40');
logo.setAttribute('height', '40');
logo.setAttribute('x', '-50');
logo.setAttribute('y', '-20');
const logoSVGRep = await fetch(import.meta.env.BASE_URL + `/logo.svg`);
const logoSVG = await logoSVGRep.text();
const temp = document.createElement('div');
temp.innerHTML = logoSVG;
const svg = temp.querySelector('svg')!;
const logo = document.createElement('g');
logo.setAttribute('transform', `translate(-60, -25)scale(0.1)`);
logo.setAttribute('font-family', 'Arial, sans-serif');
logo.innerHTML = svg.innerHTML;
info.appendChild(logo);

const rmp = document.createElementNS('http://www.w3.org/2000/svg', 'text');
rmp.setAttribute('font-family', 'Arial, sans-serif');
rmp.setAttribute('font-size', '16');
rmp.appendChild(document.createTextNode('Rail Map Painter'));
const appName = i18n.t('Rail Map Painter');
rmp.appendChild(document.createTextNode(appName));

const link = document.createElementNS('http://www.w3.org/2000/svg', 'text');
link.setAttribute('font-family', 'Arial, sans-serif');
link.setAttribute('font-size', '10');
link.setAttribute('y', '10');
link.appendChild(document.createTextNode('https://railmapgen.github.io/rmp/'));
const origin = window.location.origin;
let url = 'https://railmapgen.org/';
if (origin.includes('github')) url = 'https://railmapgen.github.io/';
else if (origin.includes('gitlab')) url = 'https://railmapgen.gitlab.io/';
url += '?app=rmp';
link.appendChild(document.createTextNode(url));

info.appendChild(logo);
info.appendChild(rmp);
Expand Down
Loading