Text is one of the basic elements for an overlay. You can overlay your video with any text content and configure text according to your requirements with Character Generator. You can vary text size, color, font etc.
To add a text item you should put your text content directly to the AddNewItem method:
string textItemId = "myTextItem"; string myTextContent = "Sample Text"; double relativeX = 0.05; double relativeY = 0.05; int isRelative = 1; int isShow = 1; myCharGen.AddNewItem(myTextContent, relativeX, relativeY, isRelative, isShow, ref textItemId);
Default XML description of text item looks like:
<cg-item id='myTextItem'> <text type='text' font='Arial' font-size='20' color='White' word-break='no'>Sample Text</text> <cg-props scale='text-scale' align='top-left' edges-smooth='0' pos-x='36' pos-y='24' show='yes' move-type='accel-both' alpha='255' bg-color='Black(0)' pixel-ar='0.' play-mode='loop' interlace='auto' width='138' height='34' pause='no'> <indent left='0' right='0' top='0' bottom='0' use-for-bg='no'/> <group-indent left='0' right='0' top='0' bottom='0'/> </cg-props> </cg-item>
Also, there is a specific method for text items - AddNewTextItem. This item contains all the same properties as AddNewItem except the 1st one - _pTextProps that is a CG_TEXT_PROPS structure (described below). With this method, you can specify text item type right in the moment of item initialization.
All the properties for text item are set in the <text> node. You can configure text item by setting each property with SetItemProperties method. Also, there is a specific method for text items - TextSetProps.
TextSetProps method contains the following fields:
- _bsItemID - text item ID
- _pItemInfo - text properties
- _bUpdateItemSize - indicates whether item size will be update after new properties are set(1 to update, 0 to ignore)
- _nMsecForChange - time for changes in milliseconds
where all the text properties are contained in _pItemInfo parameter that represents CG_TEXT_PROPS structure.
Field | XML property | Description | Values | Example |
---|---|---|---|---|
bsFontFace | font | a font that is used for the text item | any of available on the system fonts, e.g. 'Arial'. Font mode (bold, italic) is also set here, e.g.: 'Arial Bold', 'Segoe UI StrikeOut' etc. |
font='Segoe UI' |
bsTextString | no separate property. To configure text string with XML you should set all the <text> node. |
text item content | required text | <text type='text' font='Segoe UI' font-size='20' color='White' word-break='no'>Character Generator</text> |
dblOutlineWidth | outline | a thickness of item outline | thickness in pixels | outline='2' |
eTextType | type | type of text item | listed below and in eCG_TextType enumeration | type='counter' |
nDTFlags | each flag has its own XML property - described below | flags to implement formatting | listed below and in eCG_DTFlags enumeration | word-break='yes' |
nFontHeight | font-size | font size | font size units | font-size='40' |
nOutlineColor | outline-color | color of item outline | In CG_TEXT_PROPS structure is set as hex value, e.g. 0x00FFAA88. It is hard to set the color gradient with the structure so the recommended way to set color is SetItemProperties method. | outline-color='blue' |
nTextColor | color | font color | In CG_TEXT_PROPS structure is set as hex value, e.g. 0x00FFAA88. It is hard to set the color gradient with the structure so the recommended way to set color is SetItemProperties method. | color='white-red' |
- | rotate | The angle by which the element will be rotated counterclockwise | Integer number in degrees |
rotate='45' |
nTimeOffset | no appropriate property | excluded at the moment | none | none |
Text item types
Type of text item is set by 'type' property in item XML description and listed in eCG_TextType enumeration .
Value | XML property value | Description | Additional parameters | Example |
---|---|---|---|---|
eCGTT_Counter | type='counter' | Counter | counter-start - indicates from what number counter starts, counter-start='500' | <text type='counter' font='Segoe UI' font-size='36' outline-color='Black' color='White' word-break='no' counter-start='500'>00000</text> |
eCGTT_DateTime | type='date-time' | Date and time | time-offset - indicates shift in date time from current system time, time-offset='00:00:05:00' backward-offset - indicates direction of time shifting, if 'yes' - time shifts backward, backward-offset='no' |
<text type='date-time' font='Segoe UI' font-size='36' color='White' word-break='no' time-offset='00:00:00:00' backward-offset='no'>yyyy/MM/dd HH:mm:ss</text> |
eCGTT_FrameNumber | type='frame-number' | Number of received frame | None | <text type='frame-number' font='Arial' font-size='20' color='White' word-break='no'>00000</text> |
eCGTT_FrameTime | type='frame-time' | Time of received frame (video sample time) | None | <text type='frame-time' font='Arial' font-size='26' color='White' word-break='no'>0.000</text> |
eCGTT_StopWatch | type='stopwatch' | Common timer (from start time to infinity) | start-time - to indicate from what time timer should start, start-time='00:45:00:00' To specify time format you should set text content in 'HH:mm:ss' format |
<text type='stopwatch' font='Arial' font-size='26' color='White' word-break='no' pause='on' start-time='00:45:00:00'>HH:mm:ss.fff</text> |
eCGTT_Subtitles | type='subtitles' | Subtitles from SRT files | <text type='subtitles' font-face='Arial' font-size='26' align='center' fill-color='Red(255)' outline='2.7' font='Arial' outline-color='Black' color='White' word-break='no' time-offset='0'>Subtitles</text> |
|
eCGTT_Text | type='text' | Simple text | None | <text type='text' font='Times New Roman' font-size='36' outline='1.5' outline-color='Black' color='Lime' word-break='no'>Sample Text</text> |
eCGTT_Timecode | type='timecode' | Drop frame timecode of received frame | time-offset - to indicate time shifting in display timecode, time-offset='00:30:00:00' | <text type='timecode' font='Arial' font-size='26' color='White' word-break='no' time-offset='00:30:00:00'>HH:MM:SS:FF</text> |
eCGTT_Timecode_NDF | type='timecode-ndf' | Non-drop frame timecode of received frame | time-offset - to indicate time shifting in display timecode, time-offset='00:30:00:00' | <text type='timecode-ndf' font='Arial' font-size='26' color='White' word-break='no' time-offset='00:00:00:00'>HH:MM:SS:FF</text> |
eCGTT_Timer | type='timer' | Countdown (from start time to zero) timer | start-time - to indicate from what time countdown should start, start-time='00:45:00:00' To specify time format you should set text content in 'HH:mm:ss' format |
<text type='timer' font='Arial' font-size='28' color='White' word-break='no' start-time='00:46:00:00'>HH:mm:ss</text> |
Formatting flags
The flags are listed in the eCG_DTFlags enumeration.
Flag | XML property | Description | Example |
---|---|---|---|
eCGDT_BOTTOM | align='bottom' | vertical alignment for text | |
eCGDT_CENTER | align='center' | horizontal alignment for text | |
eCGDT_END_ELLIPSIS | trimming='ELL-CHAR' | ellipsis is not implemented | none |
eCGDT_FLIP_HORZ | flip='X' | horizontal mirroring of text | |
eCGDT_FLIP_VERT | flip='Y' | vertical mirroring of text | |
eCGDT_LOWERCASE | style='LOWERCASE' | lowercase script | |
eCGDT_NO_TAB | format='NO-TAB ' | ignore tabs if there is any | |
eCGDT_MEASURE_TRAILING_SPACE | format='NMTS' | do not measure trailing spaces, so if your text contains spaces in the end, e.g. 'sample text ', the spaces will be ignored with 'NMTS' setting and will be counted in case of 'MTS' | |
eCGDT_PATH_ELLIPSIS | trimming='ELL-PATH' | ellipsis is not implemented | none |
eCGDT_RIGHT | align='right' | Horizontal alignment for text | |
eCGDT_RTLREADING | format='RTL' | a right-to-left direction of text | |
eCGDT_SINGLELINE | format='SINGLE-LINE' | ignore line breaking in the source text and use it as a single line | |
eCGDT_TOP_LEFT | align='top-left' | alignment for text (both vertical and horizontal) | |
eCGDT_TRIMMING_CHAR | trimming='ELL-CHAR' | ellipsis is not implemented | none |
eCGDT_TRIMMING_WORD | trimming='ELL-WORD' | ellipsis is not implemented | none |
eCGDT_UPPERCASE | style='uppercase' | uppercase script | |
eCGDT_VCENTER | align='center' | vertical alignment for text | |
eCGDT_VERTICAL | format='VERTICAL ' | vertical text | |
eCGDT_WORD_ELLIPSIS | trimming='ELL-WORD' | ellipsis is not implemented | none |
eCGDT_WORDBREAK | word-break='yes' | Use line breaks if text is wider than item width |
Note please that you can use many flags at the same time, for example to flip text both vertically and horizontally you can set flip='XY', or in source code:
string myTextID = "myTextItem"; CG_TEXT_PROPS myTextProps; myCharGen.TextGetProps(myTextID, out myTextProps); myTextProps.nDTFlags = eCG_DTFlags.eCGDT_FLIP_HORZ & eCG_DTFlags.eCGDT_FLIP_VERT; myCharGen.TextSetProps(myTextID, ref myTextProps, 1, 0);