Preserve QPowerPoint font families
This commit is contained in:
@@ -37,6 +37,7 @@ const textColorSwatches = [
|
||||
{ color: "0F766E", label: "Зеленый текст" },
|
||||
{ color: "C2410C", label: "Красный текст" }
|
||||
];
|
||||
const slideFontFamilyOptions = ["Aptos", "Calibri", "Courier New", "Times New Roman"];
|
||||
const titleFontSizeOptions = [24, 28, 30, 34, 40, 44, 48];
|
||||
const subtitleFontSizeOptions = [14, 16, 18, 20, 22, 24, 28];
|
||||
|
||||
@@ -95,12 +96,14 @@ function slideCanvasStyle(slide: Slide) {
|
||||
return backgroundColor ? { background: `#${backgroundColor}` } : undefined;
|
||||
}
|
||||
|
||||
function slideTextStyle(color?: string, fontSize?: number): CSSProperties | undefined {
|
||||
function slideTextStyle(color?: string, fontSize?: number, fontFamily?: string): CSSProperties | undefined {
|
||||
const textColor = normalizedHexColor(color);
|
||||
const normalizedFontSize = normalizeFontSize(fontSize);
|
||||
const normalizedFamily = normalizedFontFamily(fontFamily);
|
||||
const style: CSSProperties = {
|
||||
...(textColor ? { color: `#${textColor}` } : {}),
|
||||
...(normalizedFontSize ? { fontSize: `${normalizedFontSize}pt` } : {})
|
||||
...(normalizedFontSize ? { fontSize: `${normalizedFontSize}pt` } : {}),
|
||||
...(normalizedFamily ? { fontFamily: normalizedFamily } : {})
|
||||
};
|
||||
|
||||
return Object.keys(style).length > 0 ? style : undefined;
|
||||
@@ -119,6 +122,11 @@ function normalizeFontSize(value?: number) {
|
||||
return Math.round(value * 2) / 2;
|
||||
}
|
||||
|
||||
function normalizedFontFamily(value?: string) {
|
||||
const normalized = value?.trim().replace(/["<>]/g, "").slice(0, 80) ?? "";
|
||||
return normalized && normalized.toLowerCase() !== "arial" ? normalized : "";
|
||||
}
|
||||
|
||||
function clonedSlideImages(images?: SlideImage[]) {
|
||||
const suffix = Date.now();
|
||||
return images?.map((image, index) => ({ ...image, id: `${image.id}-copy-${suffix}-${index}` }));
|
||||
@@ -392,14 +400,14 @@ export function QPowerPoint({ deck, onChange }: QPowerPointProps) {
|
||||
className="slide-title-input"
|
||||
value={activeSlide.title}
|
||||
aria-label="Заголовок слайда"
|
||||
style={slideTextStyle(activeSlide.titleColor, activeSlide.titleFontSize)}
|
||||
style={slideTextStyle(activeSlide.titleColor, activeSlide.titleFontSize, activeSlide.titleFontFamily)}
|
||||
onChange={(event) => updateSlide({ ...activeSlide, title: event.target.value })}
|
||||
/>
|
||||
<textarea
|
||||
className="slide-subtitle-input"
|
||||
value={activeSlide.subtitle}
|
||||
aria-label="Подзаголовок слайда"
|
||||
style={slideTextStyle(activeSlide.subtitleColor, activeSlide.subtitleFontSize)}
|
||||
style={slideTextStyle(activeSlide.subtitleColor, activeSlide.subtitleFontSize, activeSlide.subtitleFontFamily)}
|
||||
onChange={(event) => updateSlide({ ...activeSlide, subtitle: event.target.value })}
|
||||
/>
|
||||
<div className="slide-accent-line" />
|
||||
@@ -449,6 +457,19 @@ export function QPowerPoint({ deck, onChange }: QPowerPointProps) {
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<select
|
||||
value={activeSlide.titleFontFamily ?? ""}
|
||||
onChange={(event) => updateSlide({ ...activeSlide, titleFontFamily: event.target.value || undefined })}
|
||||
aria-label="Семейство шрифта заголовка"
|
||||
title="Семейство шрифта заголовка"
|
||||
>
|
||||
<option value="">Arial</option>
|
||||
{slideFontFamilyOptions.map((fontFamily) => (
|
||||
<option key={fontFamily} value={fontFamily}>
|
||||
{fontFamily}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<div className="slide-background-swatches" aria-label="Цвет заголовка">
|
||||
{textColorSwatches.map((swatch) => (
|
||||
<button
|
||||
@@ -475,6 +496,19 @@ export function QPowerPoint({ deck, onChange }: QPowerPointProps) {
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<select
|
||||
value={activeSlide.subtitleFontFamily ?? ""}
|
||||
onChange={(event) => updateSlide({ ...activeSlide, subtitleFontFamily: event.target.value || undefined })}
|
||||
aria-label="Семейство шрифта подзаголовка"
|
||||
title="Семейство шрифта подзаголовка"
|
||||
>
|
||||
<option value="">Arial</option>
|
||||
{slideFontFamilyOptions.map((fontFamily) => (
|
||||
<option key={fontFamily} value={fontFamily}>
|
||||
{fontFamily}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<div className="slide-background-swatches" aria-label="Цвет подзаголовка">
|
||||
{textColorSwatches.map((swatch) => (
|
||||
<button
|
||||
|
||||
Reference in New Issue
Block a user