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

fix: parse hex color and extract opacity #2233

Merged
merged 1 commit into from Mar 14, 2023
Merged

Conversation

hamed-musallam
Copy link
Member

@hamed-musallam hamed-musallam commented Mar 13, 2023

We parse the color to extract the color in hex and the alpha and convert the alpha hex value to a decimal value between 0 and 1.

export function parseColor(color: string) {
if (!color.startsWith('#')) {
return { color, opacity: 1 };
}
const hex = color.replace('#', '');
if (hex.length === 3) {
return {
color: `#${hex[0]}${hex[0]}${hex[1]}${hex[1]}${hex[2]}${hex[2]}`,
opacity: 1,
};
}
const hexOpacity = hex.slice(6) || 'FF';
const opacity =
Math.round((Number.parseInt(hexOpacity, 16) / 255) * 100) / 100;
return { color: `#${hex.slice(0, 6)}`, opacity };
}

This should solve the problem of why the spectra are not visible when the import the exported SVG to MS World

@cloudflare-pages
Copy link

cloudflare-pages bot commented Mar 13, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: b8c78b6
Status: ✅  Deploy successful!
Preview URL: https://5b7443c6.nmrium.pages.dev
Branch Preview URL: https://fix-spectra-color.nmrium.pages.dev

View logs

@hamed-musallam
Copy link
Member Author

hamed-musallam commented Mar 13, 2023

@lpatiny

WDT ? is it good for you to parse the color in this way ?

@lpatiny
Copy link
Member

lpatiny commented Mar 13, 2023

Exporting to SVG and importing to word is ok:

image

However if from word I print to PDF I obtain:

image

How can I solve this issue ?

@hamed-musallam
Copy link
Member Author

I think this issue is related to how the MS Word PDF conversion works, currently, The MS Word version that i use for the PDF exportation works perfectly!!!

#2166 (comment)

@lpatiny
Copy link
Member

lpatiny commented Mar 14, 2023

Yes we should merge this PR. It opens correctly in inkscape.

@hamed-musallam hamed-musallam merged commit 991748a into main Mar 14, 2023
@hamed-musallam hamed-musallam deleted the fix-spectra-color branch March 14, 2023 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants