Skip to content

Commit 559fdc0

Browse files
joanisedeltork
authored andcommitted
feat: creator adding custom font to read-along
1 parent 6c5f1b9 commit 559fdc0

21 files changed

+478
-236
lines changed

packages/studio-web/src/app/demo/demo.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
</read-along>
6161
</div>
6262
</div>
63-
<div class="row"></div>
63+
<div class="row mb-5"></div>
6464
<app-wc-styling></app-wc-styling>
6565
</div>
6666
</section>

packages/studio-web/src/app/demo/demo.component.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ export class DemoComponent implements OnDestroy, OnInit {
3434
this.wcStylingService.$wcStyleInput.subscribe((css) =>
3535
this.updateWCStyle(css),
3636
);
37+
this.wcStylingService.$wcStyleFonts.subscribe((font) =>
38+
this.addWCCustomFont(font),
39+
);
3740
}
3841

3942
ngOnInit(): void {}
@@ -51,7 +54,7 @@ export class DemoComponent implements OnDestroy, OnInit {
5154
this.studioService.slots,
5255
this.readalong,
5356
"Studio",
54-
this.wcStylingService.$wcStyleInput.getValue(),
57+
this.wcStylingService,
5558
);
5659
} else {
5760
this.toastr.error($localize`Download failed.`, $localize`Sorry!`, {
@@ -82,4 +85,7 @@ export class DemoComponent implements OnDestroy, OnInit {
8285
`data:text/css;base64,${this.b64Service.utf8_to_b64($event ?? "")}`,
8386
);
8487
}
88+
async addWCCustomFont($font: string) {
89+
this.readalong?.addCustomFont($font);
90+
}
8591
}

packages/studio-web/src/app/editor/editor.component.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ export class EditorComponent implements OnDestroy, OnInit, AfterViewInit {
5959
this.wcStylingService.$wcStyleInput.subscribe((css) =>
6060
this.updateWCStyle(css),
6161
);
62+
this.wcStylingService.$wcStyleFonts.subscribe((font) =>
63+
this.addWCCustomFont(font),
64+
);
6265
}
6366

6467
async ngAfterViewInit(): Promise<void> {
@@ -141,7 +144,7 @@ export class EditorComponent implements OnDestroy, OnInit, AfterViewInit {
141144
this.readalong,
142145
this.editorService.slots,
143146
this.editorService.audioB64Control$.value,
144-
this.wcStylingService.$wcStyleInput.getValue(),
147+
this.wcStylingService,
145148
);
146149
}
147150
this.hasFile = false;
@@ -159,7 +162,7 @@ export class EditorComponent implements OnDestroy, OnInit, AfterViewInit {
159162
this.editorService.slots,
160163
this.readalong,
161164
"Editor", //from
162-
this.wcStylingService.$wcStyleInput.getValue(),
165+
this.wcStylingService,
163166
);
164167
} else {
165168
this.toastr.error($localize`Download failed.`, $localize`Sorry!`, {
@@ -247,6 +250,12 @@ export class EditorComponent implements OnDestroy, OnInit, AfterViewInit {
247250
// Make Editable
248251
rasElement.setAttribute("mode", "EDIT");
249252
this.readalong = rasElement;
253+
//set custom fonts
254+
if (this.wcStylingService.$wcStyleFonts.getValue().length) {
255+
this.readalong.addCustomFont(
256+
this.wcStylingService.$wcStyleFonts.getValue(),
257+
);
258+
}
250259
const currentWord$ = await this.readalong.getCurrentWord();
251260
const alignments = await this.readalong.getAlignments();
252261
// Subscribe to the current word of the readalong and center the wavesurfer element on it
@@ -332,6 +341,7 @@ export class EditorComponent implements OnDestroy, OnInit, AfterViewInit {
332341
}
333342

334343
// stylesheet linked
344+
335345
const css = element.getAttribute("css-url");
336346
if (css !== null) {
337347
if (css.startsWith("data:text/css;base64,")) {
@@ -347,6 +357,15 @@ export class EditorComponent implements OnDestroy, OnInit, AfterViewInit {
347357
});
348358
}
349359
}
360+
} else {
361+
this.wcStylingService.$wcStyleInput.next("");
362+
}
363+
//check for custom fonts
364+
const customFont = readalong.querySelector("#ra-wc-custom-font");
365+
if (customFont !== null) {
366+
this.wcStylingService.$wcStyleFonts.next(customFont.innerHTML);
367+
} else {
368+
this.wcStylingService.$wcStyleFonts.next("");
350369
}
351370
return readalong.querySelector("body")?.innerHTML;
352371
}
@@ -454,4 +473,7 @@ export class EditorComponent implements OnDestroy, OnInit, AfterViewInit {
454473
`data:text/css;base64,${this.b64Service.utf8_to_b64($event ?? "")}`,
455474
);
456475
}
476+
async addWCCustomFont($font: string) {
477+
this.readalong?.addCustomFont($font);
478+
}
457479
}

packages/studio-web/src/app/shared/download/download.service.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
SupportedOutputs,
1818
} from "../../ras.service";
1919
import { Components } from "@readalongs/web-component/loader";
20+
import { WcStylingService } from "../wc-styling/wc-styling.service";
2021

2122
interface Image {
2223
path: string;
@@ -180,12 +181,14 @@ Please host all assets on your server, include the font and package imports defi
180181
readalong: Components.ReadAlong,
181182
slots: ReadAlongSlots,
182183
b64Audio: string,
183-
cssText: string | null,
184+
wcStylingService: WcStylingService,
184185
) {
185186
await this.updateImages(rasDoc, true, "image", readalong);
186187
await this.updateTranslations(rasDoc, readalong);
187188
let rasB64 = this.b64Service.xmlToB64(rasDoc);
188189
let b64Css = "";
190+
const cssText = wcStylingService.$wcStyleInput.getValue();
191+
const customFont = wcStylingService.$wcStyleFonts.getValue();
189192
if (cssText) {
190193
b64Css = ` css-url="data:text/css;base64,${this.b64Service.utf8_to_b64(cssText)}" `;
191194
}
@@ -225,6 +228,7 @@ Please host all assets on your server, include the font and package imports defi
225228
<meta name="generator" content="@readalongs/studio-web ${environment.packageJson.singleFileBundleVersion}">
226229
<title>${slots.title}</title>
227230
<style>${this.b64Service.jsAndFontsBundle$.value[1]}</style>
231+
<style id="ra-wc-custom-font" type="text/css">${customFont}</style>
228232
<script src="${this.b64Service.jsAndFontsBundle$.value[0]}" version="${environment.packageJson.singleFileBundleVersion}" timestamp="${environment.packageJson.singleFileBundleTimestamp}"></script>
229233
</head>
230234
<body>
@@ -260,16 +264,18 @@ Please host all assets on your server, include the font and package imports defi
260264
slots: ReadAlongSlots,
261265
readalong: Components.ReadAlong,
262266
from = "Studio",
263-
cssText: string | null,
267+
wcStylingService: WcStylingService,
264268
) {
269+
const cssText = wcStylingService.$wcStyleInput.getValue();
270+
const customFont = wcStylingService.$wcStyleFonts.getValue();
265271
if (selectedOutputFormat == SupportedOutputs.html) {
266272
var element = document.createElement("a");
267273
const blob = await this.createSingleFileBlob(
268274
rasXML,
269275
readalong,
270276
slots,
271277
b64Audio,
272-
cssText,
278+
wcStylingService,
273279
);
274280
if (blob) {
275281
const basename = this.createRASBasename(slots.title);
@@ -300,7 +306,7 @@ Please host all assets on your server, include the font and package imports defi
300306
readalong,
301307
slots,
302308
b64Audio,
303-
cssText,
309+
wcStylingService,
304310
);
305311
const basename = this.createRASBasename(slots.title);
306312

@@ -345,7 +351,7 @@ Please host all assets on your server, include the font and package imports defi
345351
const rasFile = new Blob([xmlString], { type: "application/xml" });
346352
let pathCss = "";
347353
if (cssText) {
348-
const cssFile = new Blob([cssText], { type: "text/css" });
354+
const cssFile = new Blob([customFont + cssText], { type: "text/css" });
349355
assetsFolder?.file(`${basename}.css`, cssFile);
350356
pathCss = ` css-url="assets/${basename}.css" `;
351357
}

packages/studio-web/src/app/shared/shared.module.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@ import { DownloadComponent } from "./download/download.component";
44
import { BrowserModule } from "@angular/platform-browser";
55
import { MaterialModule } from "../material.module";
66
import { FormsModule } from "@angular/forms";
7-
import {
8-
WcStylingComponent,
9-
WCStylingHelper,
10-
} from "./wc-styling/wc-styling.component";
7+
import { WcStylingComponent } from "./wc-styling/wc-styling.component";
118
@NgModule({
12-
declarations: [DownloadComponent, WcStylingComponent], //WCStylingHelper],
9+
declarations: [DownloadComponent, WcStylingComponent],
1310
imports: [BrowserModule, MaterialModule, FormsModule, CommonModule],
14-
exports: [DownloadComponent, WcStylingComponent], // WCStylingHelper],
11+
exports: [DownloadComponent, WcStylingComponent],
1512
})
1613
export class SharedModule {}

0 commit comments

Comments
 (0)