Skip to content
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
Binary file added public/fonts/inter/InterVariable.woff2
Binary file not shown.
92 changes: 92 additions & 0 deletions public/fonts/inter/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
Copyright (c) 2016 The Inter Project Authors (https://github.com/rsms/inter)

This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL

-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------

PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.

The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.

DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).

"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.

"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.

PERMISSION AND CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:

1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.

2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.

3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.

4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.

5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.

TERMINATION
This license becomes null and void if any of the above conditions are
not met.

DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
56 changes: 56 additions & 0 deletions public/fonts/inter/inter.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
@font-face {
font-family: InterVariable;
font-style: normal;
font-weight: 100 900;
font-display: swap;
src: url("InterVariable.woff2") format("woff2");
}

@font-feature-values InterVariable {
@character-variant {
cv01: 1;
cv02: 2;
cv03: 3;
cv04: 4;
cv05: 5;
cv06: 6;
cv07: 7;
cv08: 8;
cv09: 9;
cv10: 10;
cv11: 11;
cv12: 12;
cv13: 13;
alt-1: 1; /* Alternate one */
alt-3: 9; /* Flat-top three */
open-4: 2; /* Open four */
open-6: 3; /* Open six */
open-9: 4; /* Open nine */
lc-l-with-tail: 5; /* Lower-case L with tail */
simplified-u: 6; /* Simplified u */
alt-double-s: 7; /* Alternate German double s */
uc-i-with-serif: 8; /* Upper-case i with serif */
uc-g-with-spur: 10; /* Capital G with spur */
single-story-a: 11; /* Single-story a */
compact-lc-f: 12; /* Compact f */
compact-lc-t: 13; /* Compact t */
}
@styleset {
ss01: 1;
ss02: 2;
ss03: 3;
ss04: 4;
ss05: 5;
ss06: 6;
ss07: 7;
ss08: 8;
open-digits: 1; /* Open digits */
disambiguation: 2; /* Disambiguation (with zero) */
disambiguation-except-zero: 4; /* Disambiguation (no zero) */
round-quotes-and-commas: 3; /* Round quotes & commas */
square-punctuation: 7; /* Square punctuation */
square-quotes: 8; /* Square quotes */
circled-characters: 5; /* Circled characters */
squared-characters: 6; /* Squared characters */
}
}
1 change: 1 addition & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ main {

strong {
color: $secondary-color;
font-weight: 600;
}

.bi-arrow-down-square-fill {
Expand Down
2 changes: 1 addition & 1 deletion src/assets/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ $background-dark: #e5e5e5; // Mörk bakgrund
$background-input: #ffffff; // Bakgrund för inmatningsfält

// Typografi
$font-family-base: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
$font-family-base: InterVariable, sans-serif;
$font-family-serif: "EB Garamond", serif;
$font-family-sans: "FreeSans", sans-serif;

Expand Down
1 change: 1 addition & 0 deletions src/assets/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ body {
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-optical-sizing: auto;
}

// För tillgänglighet
Expand Down
6 changes: 3 additions & 3 deletions src/assets/main.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import "@/assets/_variables.scss";
@import "@/assets/base.scss";
@import "$fonts/inter/inter.css";
@import "$fonts/ebgaramond/EBGaramond.css";
@import "$fonts/freesans/FreeSans.css";

Expand Down Expand Up @@ -78,16 +79,15 @@ $bootstrap-icons-font-dir: "bootstrap-icons/font/fonts";
outline-offset: 2px;
box-shadow: 0 0 0 0.25rem rgba($primary-color, 0.25);
}
}

.btn {
// Knappar med ikoner
&:has(i.bi), &:has(img) {
display: flex;
align-items: center;
}

// Knapp-ikoner
i.bi, img {
// Knapp-ikoner
margin-right: var(--bs-btn-padding-x);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/components/tools/ToolsFinish.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import SendWizard from "@/components/tools/finish/send/SendWizard.vue";
import FinalizeWizard from "@/components/tools/finish/finalize/FinalizeWizard.vue";
import { getConfigValue } from "@/util/configUtils.ts";
import type { TodoList } from "@/model/todolist/TodoList.ts";
import { RENDER_FONT_FAMILY_WHITELIST } from "@/util/renderUtils.ts";

const props = defineProps<{
/** Årsredovisningen som ska exporteras. */
Expand All @@ -39,6 +40,7 @@ async function getIXBRL(): Promise<string | undefined> {
return await convertVueHTMLToiXBRL(
arsredovisningForExport,
`${foretagsinformation.organisationsnummer} ${foretagsinformation.foretagsnamn} - Årsredovisning`,
RENDER_FONT_FAMILY_WHITELIST,
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { ComponentExposed } from "vue-component-type-helpers";
import RenderMain from "@/components/render/RenderMain.vue";
import type { Arsredovisning } from "@/model/arsredovisning/Arsredovisning.ts";
import type { Ref } from "vue";
import { RENDER_FONT_FAMILY_WHITELIST } from "@/util/renderUtils.ts";

/**
* Argument som krävs för att generera en iXBRL-årsredovisning.
Expand Down Expand Up @@ -42,6 +43,7 @@ function tryGenerateIXBRLInInterval(args: Args) {
args.ixbrlOutput.value = await convertVueHTMLToiXBRL(
arsredovisningRoot,
`${foretagsinformation.organisationsnummer} ${foretagsinformation.foretagsnamn} - Årsredovisning`,
RENDER_FONT_FAMILY_WHITELIST,
);
}
}, 250);
Expand Down
28 changes: 24 additions & 4 deletions src/util/documentUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@
* @param rootElement - HTML-elementet som ska konverteras. Elementets innehåll
* bearbetas och omvandlas till iXBRL-format.
* @param title - Titeln på det resulterande iXBRL-dokumentet.
* @param fontFamilyWhitelist - En lista med typsnitt som får bäddas in i
* iXBRL-dokumentet.
* @returns En sträng som representerar det konverterade iXBRL-innehållet.
*/
export async function convertVueHTMLToiXBRL(
rootElement: HTMLElement,
title: string,
fontFamilyWhitelist: string[],
): Promise<string> {
const doc = new DOMParser().parseFromString(
rootElement.innerHTML,
"text/html",
);

// Lägg till CSS
let rulesCss = await getCssTextForUsedRules(doc);
let rulesCss = await getCssTextForUsedRules(doc, fontFamilyWhitelist);

// Omvandla CSS-attribut som inte är kompatibla med wkhtmltopdf som Bolagsverket använder
rulesCss = rulesCss.replace(
Expand Down Expand Up @@ -154,10 +157,15 @@
* det angivna dokumentet.
*
* @param doc - Ett dokument som ska kontrolleras för matchande CSS-regler.
* @param fontFamilyWhitelist - En lista med typsnitt som får bäddas in i
* iXBRL-dokumentet.
* @returns En sträng som innehåller den sammanfogade CSS-texten för alla
* matchande regler.
*/
async function getCssTextForUsedRules(doc: Document): Promise<string> {
async function getCssTextForUsedRules(

Check failure on line 165 in src/util/documentUtils.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 24 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=GredorTools_gredor-frontend&issues=AZzEMfnSlgOlHtCVoMh-&open=AZzEMfnSlgOlHtCVoMh-&pullRequest=62
doc: Document,
fontFamilyWhitelist: string[],
): Promise<string> {
const rulesUsed = new Set<CSSRule>();
const fontFamiliesUsed = new Set<string>();

Expand Down Expand Up @@ -212,7 +220,8 @@
rulesCss += rule.cssText + "\n";
}

const fontReferencesInDocument = await getFontReferencesInDocument();
const fontReferencesInDocument =
await getFontReferencesInDocument(fontFamilyWhitelist);
for (const fontReference of fontReferencesInDocument) {
if (fontFamiliesUsed.has(fontReference.fontFamily)) {
rulesCss += `
Expand All @@ -235,6 +244,8 @@
* CSS-stilmallar i dokumentet och extraherar detaljer som fontfamilj, vikt,
* stil, källa (src) och unicode-område.
*
* @param fontFamilyWhitelist - En lista med typsnitt som får bäddas in i
* iXBRL-dokumentet.
* @returns En array med objekt som innehåller typsnittsinformation:
* - fontFamily: Namnet på typsnittet.
* - fontWeight: Vikten för typsnittet, t.ex. 400 för normal vikt.
Expand All @@ -243,7 +254,7 @@
* - srcBase64: Källa till typsnittet i base64-format.
* - unicodeRange: Det unicode-intervall som typsnittet gäller för.
*/
async function getFontReferencesInDocument() {
async function getFontReferencesInDocument(fontFamilyWhitelist: string[]) {
// Ursprunglig källa: https://stackoverflow.com/a/75857870

const fontFiles: Array<{
Expand Down Expand Up @@ -274,6 +285,15 @@
const src = style.getPropertyValue("src");
const unicodeRange = style.getPropertyValue("unicode-range");

// Kolla att aktuell fontFamily får bäddas in i iXBRL-dokumentet
if (
!fontFamilyWhitelist
.map((ff) => ff.toLowerCase())
.includes(fontFamily.toLowerCase())
) {
continue;
}

// Konvertera till base64
const urlMatches = new RegExp(/\(([^)]+)\)/).exec(src.split(",")[0]);
const url = urlMatches ? urlMatches[1].replace(/"/g, "") : "";
Expand Down
2 changes: 2 additions & 0 deletions src/util/renderUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ export function isPercentageBelopprad(belopprad: Belopprad): boolean {
return PERCENTAGE_TAXONOMY_ITEMS.includes(belopprad.taxonomyItemName);
}

export const RENDER_FONT_FAMILY_WHITELIST = ["EB Garamond", "FreeSans"];

const PERCENTAGE_TAXONOMY_ITEMS = [
"se-gen-base:Soliditet",
"se-gen-base:Rorelsemarginal",
Expand Down