Mako 8.2.0 API
MakoCore SDK API Documentation
Loading...
Searching...
No Matches
layout.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2023-2025 Global Graphics Software Ltd. All rights reserved.
3 */
4
5#ifndef JAWSMAKO_LAYOUT_H
6#define JAWSMAKO_LAYOUT_H
7
8#include <utility>
9#include <cstdint>
10#include <edl/idomcolor.h>
11#include <edl/idomfont.h>
12#include <jawsmako/types.h>
13
14namespace JawsMako
15{
16 using namespace EDL;
17
18 // Forward declarations
19 class ILayout;
21 class ILayoutFrame;
23 class ILayoutParagraph;
26 class ILayoutRun;
28 class ILayoutTextRun;
30 class ILayoutImageRun;
33 class ILayoutFont;
37
43 class ILayoutFrame : public IRCObject
44 {
45 public:
46 virtual ~ILayoutFrame() {}
47
57
64 static JAWSMAKO_API ILayoutFramePtr create(const FRect &bounds,
65 eVerticalAlignment verticalAlignment = eVATop);
66
72 virtual ILayoutFramePtr clone() const = 0;
73
78 virtual const FRect &getBounds() const = 0;
79
85 };
86
93 {
94 public:
95 virtual ~ILayoutParagraph() {}
96
107
126 static JAWSMAKO_API ILayoutParagraphPtr create(eHorizontalAlignment horizontalAlignment = eHALeft,
127 double spacingAfter = 0.0, double spacingBefore = 0.0,
128 double leading = 1.0,
129 const IDOMColorPtr &defaultColor = IDOMColorPtr(),
130 const ILayoutFontPtr &defaultFont = ILayoutFontPtr(),
131 bool exact = true,
132 double defaultFontSize = -1.0);
133
151 static JAWSMAKO_API ILayoutParagraphPtr create(eHorizontalAlignment horizontalAlignment,
152 double spacingAfter, double spacingBefore,
153 double leading,
154 const IDOMColorPtr &defaultColor,
155 const IDOMFontOpenTypePtr &defaultFont,
156 uint32 defaultFontIndex = 0,
157 double defaultFontSize = -1.0);
158
166 virtual ILayoutParagraphPtr clone() const = 0;
167
172 virtual void addRun(const ILayoutRunPtr &run) = 0;
173
181 virtual const CLayoutRunVect &getRuns() const = 0;
182
188
195 virtual void setSpacing(double spacing, bool before = false) = 0;
196
203 virtual double getSpacing(bool before = false) const = 0;
204
212 virtual void setLeading(double leading) = 0;
213
219 virtual double getLeading() const = 0;
220
231 virtual void setDefaultFont(const ILayoutFontPtr &defaultFont, bool exact = true) = 0;
232
240 virtual void setDefaultFont(const IDOMFontOpenTypePtr &defaultFont,
241 uint32 defaultFontIndex) = 0;
242
243
248 virtual const IDOMFontOpenTypePtr &getDefaultFont() const = 0;
249
254 virtual uint32 getDefaultFontIndex() const = 0;
255
261 virtual void setDefaultFontSize(double defaultFontSize) = 0;
262
267 virtual double getDefaultFontSize() const = 0;
268
273 virtual void setDefaultColor(const IDOMColorPtr &defaultColor) = 0;
274
279 virtual const IDOMColorPtr &getDefaultColor() const = 0;
280
286 virtual void addBreak() = 0;
287 };
288
294 class ILayoutRun : public IRCObject
295 {
296 public:
297 virtual ~ILayoutRun() {}
298 };
299
306 {
307 public:
308 virtual ~ILayoutTextRun() {}
309
323 static JAWSMAKO_API ILayoutTextRunPtr create(const U8String &text,
324 const IDOMFontOpenTypePtr &font,
325 uint32 fontIndex,
326 double size,
327 const IDOMColorPtr &color = IDOMColorPtr(),
328 double letterSpacing = 0.0);
329
346 static JAWSMAKO_API ILayoutTextRunPtr create(const String &text,
347 const IDOMFontOpenTypePtr &font,
348 uint32 fontIndex,
349 double size,
350 const IDOMColorPtr &color = IDOMColorPtr(),
351 double letterSpacing = 0.0);
352
372 static JAWSMAKO_API ILayoutTextRunPtr create(const U8String &text,
373 const ILayoutFontPtr &font,
374 double size,
375 bool exact = true,
376 const IDOMColorPtr &color = IDOMColorPtr(),
377 double letterSpacing = 0.0);
378
398 static JAWSMAKO_API ILayoutTextRunPtr create(const String &text,
399 const ILayoutFontPtr &font,
400 double size,
401 bool exact = true,
402 const IDOMColorPtr &color = IDOMColorPtr(),
403 double letterSpacing = 0.0);
404
422 static JAWSMAKO_API ILayoutTextRunPtr create(const IJawsMakoPtr &jawsMako,
423 const U8String &text,
424 const U8String &fontName,
425 double size,
426 const IDOMColorPtr &color = IDOMColorPtr(),
427 double letterSpacing = 0.0);
428
446 static JAWSMAKO_API ILayoutTextRunPtr create(const IJawsMakoPtr &jawsMako,
447 const String &text,
448 const U8String &fontName,
449 double size,
450 const IDOMColorPtr &color = IDOMColorPtr(),
451 double letterSpacing = 0.0);
452
457 virtual const U8String &getText() const = 0;
458
463 virtual const IDOMFontOpenTypePtr &getFont() const = 0;
464
469 virtual uint32 getFontIndex() const = 0;
470
475 virtual double getSize() const = 0;
476
481 virtual void setColor(const IDOMColorPtr &color) = 0;
482
487 virtual const IDOMColorPtr &getColor() const = 0;
488
493 virtual void setLetterSpacing(double letterSpacing) = 0;
494
499 virtual double getLetterSpacing() const = 0;
500
501 };
502 #define obj2ILayoutTextRun(obj) ILayoutTextRunPtr(dynamic_cast<ILayoutTextRun *>((IRCObject *) obj), true)
503
510 {
511 public:
512 virtual ~ILayoutImageRun() {}
513
525 static JAWSMAKO_API ILayoutImageRunPtr create(const IJawsMakoPtr &jawsMako, const IDOMImagePtr &image, double width = 0.0, double height = 0.0);
526
531 virtual const IDOMImagePtr &getImage() const = 0;
532
537 virtual double getWidth() const = 0;
538
543 virtual double getHeight() const = 0;
544 };
545 #define obj2ILayoutImageRun(obj) ILayoutImageRunPtr(dynamic_cast<ILayoutImageRun *>((IRCObject *) obj), true)
546
553 {
554 public:
556
562 typedef enum
563 {
564 eAny = 0,
565 eThin = 100,
567 eLight = 300,
569 eNormal = 400,
570 eMedium = 500,
571 eSemiBold = 600,
572 eBold = 700,
574 eBlack = 900,
576 } eFontWeight;
577
585 static JAWSMAKO_API ILayoutFontWeightPtr create(uint16 weight = eAny, uint16 allowedError = 0);
586
594 static JAWSMAKO_API ILayoutFontWeightPtr createFromVect(const CUInt16Vect &weights, uint16 allowedError = 0);
595
603 static JAWSMAKO_API ILayoutFontWeightPtr createFromRange(uint16 weightLow, uint16 weightHigh);
604
612 virtual bool match(uint16 weight) const = 0;
613
624 virtual uint16 difference(uint16 weight) const = 0;
625
631 virtual bool equals(const ILayoutFontWeightPtr &weight) const = 0;
632 };
633 #define obj2ILayoutFontWeight(obj) ILayoutFontWeightPtr(dynamic_cast<ILayoutFontWeight *>((IRCObject *) obj), true)
634
643 class ILayoutFont : public IRCObject
644 {
645 public:
646 virtual ~ILayoutFont() {}
647
651 typedef enum
652 {
656 } eFontStyle;
657
667
677
698 static JAWSMAKO_API ILayoutFontPtr create(const IJawsMakoPtr &jawsMako,
699 const ILayoutFontWeightPtr &weight = ILayoutFontWeightPtr(),
700 eFontStyle style = eFSAny,
701 eFontProportion proportion = eFPAny,
702 eFontSerifStyle serifStyle = eFSSAny,
703 uint64 codePage = UINT64_MAX);
704
705 /*
706 * @brief Set the font weight.
707 *
708 * @param weight Weights used when finding fonts.
709 */
710 virtual void setWeight(const ILayoutFontWeightPtr &weight) = 0;
711
712 /*
713 * @brief Set the font style.
714 *
715 * @param style The style to be used when finding fonts.
716 */
717 virtual void setStyle(eFontStyle style) = 0;
718
719 /*
720 * @brief Set the font proportion type.
721 *
722 * @param proportion The proportion type used when finding fonts.
723 */
724 virtual void setProportion(eFontProportion proportion) = 0;
725
726 /*
727 * @brief Set the serif style.
728 *
729 * @param serifStyle The Serif style used when finding fonts.
730 */
731 virtual void setSerif(eFontSerifStyle serifStyle) = 0;
732
733 /*
734 * @brief Set the code page ranges.
735 *
736 * @param codePage The code page character ranges used when finding fonts.
737 */
738 virtual void setCodePage(uint64 codePage) = 0;
739
745 {
746 public:
747 IDOMFontOpenTypePtr domFont;
749
750 CLayoutFontItem (const IDOMFontOpenTypePtr &domFont, uint32 fontIndex)
751 {
752 this->domFont = domFont;
753 this->fontIndex = fontIndex;
754 }
755
757 {
758 fontIndex = 0;
759 }
760
761 bool operator== (const CLayoutFontItem &other) const
762 {
763 return (other.domFont == domFont)
764 && (other.fontIndex == fontIndex);
765 }
766
767 bool operator!= (const CLayoutFontItem &other) const
768 {
769 return ! (*this == other);
770 }
771
772 bool operator< (const CLayoutFontItem &other) const
773 {
774 if (domFont == other.domFont)
775 return fontIndex < other.fontIndex;
776 else
777 return domFont < other.domFont;
778 }
779
780 };
781
783
788 virtual CLayoutFontVect findFonts() const = 0;
789
800 virtual void findFont(IDOMFontOpenTypePtr &font, uint32 &fontIndex, bool exact = true) const = 0;
801 };
802 #define obj2ILayoutFont(obj) ILayoutFontPtr(dynamic_cast<ILayoutFont *>((IRCObject *) obj), true)
803
811 class ILayout : public IRCObject
812 {
813 public:
814 virtual ~ILayout() {}
815
821 static JAWSMAKO_API ILayoutPtr create(const IJawsMakoPtr &jawsMako);
822
834 static JAWSMAKO_API ILayoutPtr createWithFrame(const IJawsMakoPtr &jawsMako,
835 const FRect &frameBounds,
837
844 virtual void addFrame(const ILayoutFramePtr &frame) = 0;
845
852 virtual IDOMNodePtr layout(const CLayoutParagraphVect &paragraphs) = 0;
853
862 virtual IDOMNodePtr layout(const ILayoutParagraphPtr &paragraph) = 0;
863
877 virtual IDOMNodePtr layout(const ILayoutRunPtr &run,
878 ILayoutParagraph::eHorizontalAlignment horizontalAlignment,
879 double spacingAfter = 0.0,
880 double spacingBefore = 0.0,
881 double leading = 1.0) = 0;
882 };
883}
884#endif
Definition edlvector.h:30
Base class Interface for all Reference Counted objects.
Definition ircobject.h:35
bool operator==(const CLayoutFontItem &other) const
Definition layout.h:761
CLayoutFontItem()
Definition layout.h:756
IDOMFontOpenTypePtr domFont
Definition layout.h:747
bool operator!=(const CLayoutFontItem &other) const
Definition layout.h:767
bool operator<(const CLayoutFontItem &other) const
Definition layout.h:772
CLayoutFontItem(const IDOMFontOpenTypePtr &domFont, uint32 fontIndex)
Definition layout.h:750
uint32 fontIndex
Definition layout.h:748
ILayoutFont interface.
Definition layout.h:644
virtual ~ILayoutFont()
Definition layout.h:646
virtual void findFont(IDOMFontOpenTypePtr &font, uint32 &fontIndex, bool exact=true) const =0
Find matching font.
virtual CLayoutFontVect findFonts() const =0
Find matching fonts.
virtual void setCodePage(uint64 codePage)=0
virtual void setWeight(const ILayoutFontWeightPtr &weight)=0
CEDLVector< CLayoutFontItem > CLayoutFontVect
Definition layout.h:782
eFontSerifStyle
Font serif style.
Definition layout.h:672
@ eFSSSansSerif
Sans Serif.
Definition layout.h:675
@ eFSSSerif
Serif.
Definition layout.h:674
@ eFSSAny
Match against any style.
Definition layout.h:673
static JAWSMAKO_API ILayoutFontPtr create(const IJawsMakoPtr &jawsMako, const ILayoutFontWeightPtr &weight=ILayoutFontWeightPtr(), eFontStyle style=eFSAny, eFontProportion proportion=eFPAny, eFontSerifStyle serifStyle=eFSSAny, uint64 codePage=UINT64_MAX)
Create a ILayoutFont instance.
virtual void setSerif(eFontSerifStyle serifStyle)=0
eFontStyle
Font style.
Definition layout.h:652
@ eFSItalic
Italic.
Definition layout.h:654
@ eFSRegular
Regular.
Definition layout.h:655
@ eFSAny
Match against any style.
Definition layout.h:653
eFontProportion
Font proportion.
Definition layout.h:662
@ eFPAny
Match against any proportion type.
Definition layout.h:663
@ eFPMonoSpaced
Monospace (fixed-width) font.
Definition layout.h:664
@ eFPProportional
Proportional (variable-width) font.
Definition layout.h:665
virtual void setProportion(eFontProportion proportion)=0
virtual void setStyle(eFontStyle style)=0
Font weights used by ILayoutFont for font selection.
Definition layout.h:553
virtual bool equals(const ILayoutFontWeightPtr &weight) const =0
Determines if the given weight instance is equivalent to this instance.
static JAWSMAKO_API ILayoutFontWeightPtr createFromVect(const CUInt16Vect &weights, uint16 allowedError=0)
Create a font weight instance using a vector of weight values.
virtual bool match(uint16 weight) const =0
Test for a matching font weight.
eFontWeight
Font weight.
Definition layout.h:563
@ eExtraBold
Extra Bold.
Definition layout.h:573
@ eBlack
Black.
Definition layout.h:574
@ eThin
Thin.
Definition layout.h:565
@ eAny
Match against any weight.
Definition layout.h:564
@ eLight
Light.
Definition layout.h:567
@ eSemiBold
Semi Bold.
Definition layout.h:571
@ eMedium
Medium.
Definition layout.h:570
@ eExtraBlack
Extra Black.
Definition layout.h:575
@ eNormal
Normal.
Definition layout.h:569
@ eSemiLight
Semi Light.
Definition layout.h:568
@ eBold
Bold.
Definition layout.h:572
@ eExtraLight
Extra Light.
Definition layout.h:566
virtual uint16 difference(uint16 weight) const =0
Find the font weight difference.
static JAWSMAKO_API ILayoutFontWeightPtr createFromRange(uint16 weightLow, uint16 weightHigh)
Create a font weight instance using a range of weight values.
virtual ~ILayoutFontWeight()
Definition layout.h:555
static JAWSMAKO_API ILayoutFontWeightPtr create(uint16 weight=eAny, uint16 allowedError=0)
Create a font weight instance using a single weight value.
Definition layout.h:44
virtual const FRect & getBounds() const =0
Get the bounds of this frame.
eVerticalAlignment
Vertical alignment for this frame.
Definition layout.h:52
@ eVABottom
Align vertically to the bottom of the frame.
Definition layout.h:55
@ eVATop
Align vertically to the top of the frame.
Definition layout.h:53
@ eVACenter
Align vertically centered.
Definition layout.h:54
static JAWSMAKO_API ILayoutFramePtr create(const FRect &bounds, eVerticalAlignment verticalAlignment=eVATop)
Create a frame.
virtual ~ILayoutFrame()
Definition layout.h:46
virtual ILayoutFramePtr clone() const =0
Clone the frame.
virtual eVerticalAlignment getVerticalAlignment() const =0
Get the vertical alignment of the content of this frame.
An instance of a Layout engine that can layout and flow text into one or more frames,...
Definition layout.h:812
virtual ~ILayout()
Definition layout.h:814
static JAWSMAKO_API ILayoutPtr createWithFrame(const IJawsMakoPtr &jawsMako, const FRect &frameBounds, ILayoutFrame::eVerticalAlignment frameVerticalAlignment=ILayoutFrame::eVACenter)
Create an instance of the layout engine with a frame.
virtual IDOMNodePtr layout(const ILayoutRunPtr &run, ILayoutParagraph::eHorizontalAlignment horizontalAlignment, double spacingAfter=0.0, double spacingBefore=0.0, double leading=1.0)=0
Lay out a run of content.
virtual void addFrame(const ILayoutFramePtr &frame)=0
Add a frame to the list of frames into which the engine will flow content. Content will be laid out i...
virtual IDOMNodePtr layout(const ILayoutParagraphPtr &paragraph)=0
Lay out a single paragraph.
static JAWSMAKO_API ILayoutPtr create(const IJawsMakoPtr &jawsMako)
Create an instance of the layout engine.
virtual IDOMNodePtr layout(const CLayoutParagraphVect &paragraphs)=0
Lay out the given paragraphs into the frames, returning a DOM representation of the result.
A run of image content to be added to an ILayoutParagraph.
Definition layout.h:510
virtual double getWidth() const =0
Get the width of the image.
virtual const IDOMImagePtr & getImage() const =0
Get the image.
virtual ~ILayoutImageRun()
Definition layout.h:512
static JAWSMAKO_API ILayoutImageRunPtr create(const IJawsMakoPtr &jawsMako, const IDOMImagePtr &image, double width=0.0, double height=0.0)
Create an image run.
virtual double getHeight() const =0
Get the height of the image.
A paragraph, consisting of a number of runs of content.
Definition layout.h:93
virtual void setDefaultFont(const ILayoutFontPtr &defaultFont, bool exact=true)=0
Set an ILayoutFont instance to select a default font for the the paragraph, or nullptr to clear the d...
virtual const CLayoutRunVect & getRuns() const =0
Get the runs present in this paragraph.
virtual uint32 getDefaultFontIndex() const =0
Get the font index within the default font file.
virtual void setDefaultFont(const IDOMFontOpenTypePtr &defaultFont, uint32 defaultFontIndex)=0
Set an the default font for the paragraph, or nullptr to clear the default.
virtual double getSpacing(bool before=false) const =0
Get the paragraph spacing.
virtual const IDOMFontOpenTypePtr & getDefaultFont() const =0
Get the default font for the paragraph.
virtual double getLeading() const =0
Get the leading (line spacing).
static JAWSMAKO_API ILayoutParagraphPtr create(eHorizontalAlignment horizontalAlignment=eHALeft, double spacingAfter=0.0, double spacingBefore=0.0, double leading=1.0, const IDOMColorPtr &defaultColor=IDOMColorPtr(), const ILayoutFontPtr &defaultFont=ILayoutFontPtr(), bool exact=true, double defaultFontSize=-1.0)
Create a paragraph.
virtual eHorizontalAlignment getHorizontalAlignment() const =0
Get the horizontal alignment for this paragraph.
virtual const IDOMColorPtr & getDefaultColor() const =0
Get the default color for the paragraph.
virtual void setLeading(double leading)=0
Set the leading (line spacing).
virtual ~ILayoutParagraph()
Definition layout.h:95
virtual void addRun(const ILayoutRunPtr &run)=0
Add a run to the end of the paragraph.
eHorizontalAlignment
Horizontal alignment or justification for the paragraph.
Definition layout.h:101
@ eHACenter
Align the content to the center of the enclosing frame.
Definition layout.h:103
@ eHAJustified
Justify the content left and right.
Definition layout.h:105
@ eHARight
Align the content to the right boundary of the enclosing frame.
Definition layout.h:104
@ eHALeft
Align the content to the left boundary of the enclosing frame.
Definition layout.h:102
virtual ILayoutParagraphPtr clone() const =0
Clone the paragraph.
static JAWSMAKO_API ILayoutParagraphPtr create(eHorizontalAlignment horizontalAlignment, double spacingAfter, double spacingBefore, double leading, const IDOMColorPtr &defaultColor, const IDOMFontOpenTypePtr &defaultFont, uint32 defaultFontIndex=0, double defaultFontSize=-1.0)
Create a paragraph.
virtual double getDefaultFontSize() const =0
Get the default font size on DOM units.
virtual void setDefaultFontSize(double defaultFontSize)=0
Set the default font size of the paragraph.
virtual void addBreak()=0
Add a break to the end of the paragraph.
virtual void setSpacing(double spacing, bool before=false)=0
Set the paragraph spacing.
virtual void setDefaultColor(const IDOMColorPtr &defaultColor)=0
Set a default color for the paragraph, or nullptr to clear the default.
A run of content to be added to an ILayoutParagraph.
Definition layout.h:295
virtual ~ILayoutRun()
Definition layout.h:297
A run of text content to be added to an ILayoutParagraph.
Definition layout.h:306
virtual const IDOMColorPtr & getColor() const =0
Get the text color.
virtual double getSize() const =0
Get the em size of the font in default DOM units (96ths of an inch)
virtual const IDOMFontOpenTypePtr & getFont() const =0
Get the font.
virtual uint32 getFontIndex() const =0
Get the font index within the font file.
virtual double getLetterSpacing() const =0
Get the letter spacing.
static JAWSMAKO_API ILayoutTextRunPtr create(const IJawsMakoPtr &jawsMako, const U8String &text, const U8String &fontName, double size, const IDOMColorPtr &color=IDOMColorPtr(), double letterSpacing=0.0)
Create a text run.
static JAWSMAKO_API ILayoutTextRunPtr create(const String &text, const IDOMFontOpenTypePtr &font, uint32 fontIndex, double size, const IDOMColorPtr &color=IDOMColorPtr(), double letterSpacing=0.0)
Create a text run.
virtual void setColor(const IDOMColorPtr &color)=0
Set the text color.
static JAWSMAKO_API ILayoutTextRunPtr create(const U8String &text, const IDOMFontOpenTypePtr &font, uint32 fontIndex, double size, const IDOMColorPtr &color=IDOMColorPtr(), double letterSpacing=0.0)
Create a text run.
virtual const U8String & getText() const =0
Get the text in the run as UTF-8.
static JAWSMAKO_API ILayoutTextRunPtr create(const U8String &text, const ILayoutFontPtr &font, double size, bool exact=true, const IDOMColorPtr &color=IDOMColorPtr(), double letterSpacing=0.0)
Create a text run.
virtual void setLetterSpacing(double letterSpacing)=0
Set the letter spacing.
static JAWSMAKO_API ILayoutTextRunPtr create(const IJawsMakoPtr &jawsMako, const String &text, const U8String &fontName, double size, const IDOMColorPtr &color=IDOMColorPtr(), double letterSpacing=0.0)
Create a text run.
virtual ~ILayoutTextRun()
Definition layout.h:308
static JAWSMAKO_API ILayoutTextRunPtr create(const String &text, const ILayoutFontPtr &font, double size, bool exact=true, const IDOMColorPtr &color=IDOMColorPtr(), double letterSpacing=0.0)
Create a text run.
RectTmpl< double > FRect
Definition edlgeom.h:338
unsigned short uint16
Definition edltypes.h:33
unsigned int uint32
Definition edltypes.h:34
unsigned long long uint64
Definition edltypes.h:35
EDLSysString U8String
A UTF-8 String.
Definition types.h:144
EDLString String
A wide character string (UTF-16 on Windows, UTF-32 on all other platforms)
Definition types.h:138
Definition apexcustompostprocess.h:17
CEDLVector< uint16 > CUInt16Vect
Definition types.h:179
CEDLVector< ILayoutParagraphPtr > CLayoutParagraphVect
Definition layout.h:25
CEDLVector< ILayoutRunPtr > CLayoutRunVect
Definition layout.h:32
#define DECL_SMART_PTR(cls)
Definition smartptr.h:211
#define JAWSMAKO_API
Definition types.h:29