AliyunPlayer v7.11.0
Aliyun Player API Reference Manual for iOS Platforms
Loading...
Searching...
No Matches
AliVttRenderImpl Class Reference

VTT subtitle rendering implementation class. More...

#include "AliVttSubtitleView.h"

Inheritance diagram for AliVttRenderImpl:

Instance Methods

(void) - actualShow:withContext:
 Actually display subtitle.
 
(void) - applyBackgroundColorStyle:contentAttribute:
 Apply background color style.
 
(void) - applyColorStyle:contentAttribute:
 Apply text color style.
 
(void) - applyDecorationStyle:contentAttribute:
 Apply text decoration styles (underline, strikethrough, etc.)
 
(void) - applyFontStyle:contentAttribute:context:
 Apply font style.
 
(void) - applyLayerSetting:styleStr:
 Apply layer settings.
 
(void) - applyStrokeAndShadow:contentAttribute:context:
 Apply stroke and shadow effects.
 
(CGFloat) - calculateMaxTextWidth
 Calculate maximum text width.
 
(void) - clear
 Clear all subtitle display content.
 
(BOOL) - containsFullWidthCharacters:
 Detect if string contains full-width characters.
 
(BOOL) - containsUpperGlyphCharacters:
 Detect if string contains superscript characters.
 
(NSAttributedString *) - createStyledText:dialogueObj:withContext:
 Create styled attributed text.
 
(NSAttributedString *) - createStyledTextSegment:context:
 Create styled string for single text segment.
 
(void) - customizeAttribuets:locationAttribute:
 Customize content attributes and location information (for subclass override)
 
(UIFont *) - customizeFont:contentAttribute:contentText:
 Customize font (for subclass override)
 
(void) - customizeParagraphStyle:withFont:contentText:
 Customize paragraph style (for subclass override)
 
(AliVttDialogueObj *) - findDialogueObjByIdx:
 Find subtitle dialogue object by index.
 
(AliVttDialogueObj *) - findIdleDialogueObj
 Find idle subtitle dialogue object.
 
(UIFont *) - generateFontWithName:fontSize:isBold:isItalic:
 Generate font with specified style.
 
(void) - getActualTextPositions:withContext:
 Calculate subtitle display position.
 
(void) - getActualTextSize:dialogue:withContext:
 Calculate actual text size.
 
(UIColor *) - getColorFromValue:
 Create UIColor object from integer value.
 
(void) - getParentViewSize:h:
 Get parent view size.
 
(CGSize) - getSizeFromStr:withMaxtextWidth:
 Calculate display size of attributed text.
 
(nullable AliWebVttHeader *) - getVttHeader
 Get VTT header information.
 
(void) - hideDialogue:atIndex:
 Hide subtitle at specified index.
 
(void) - initialDialogueObj:index:
 Initialize subtitle dialogue object.
 
(CGPoint) - maybeApplyDefaultPosition:withContext:
 Apply default position rules.
 
(CGFloat) - maybeForcebeCenter:withContext:
 Force center alignment (when position is out of range)
 
(CGFloat) - maybeUpperThanBase:withContext:
 Ensure position is above baseline.
 
(RenderContext *) - prepareRenderContext
 Prepare rendering context.
 
(CGPoint) - processAttributePosition:withContext:
 Process location attributes and calculate base coordinates.
 
(CGFloat) - processXPositon:withContext:
 Process X direction position.
 
(CGFloat) - processYPosition:withContext:
 Process Y direction position.
 
(void) - renderSubtitleContent:contentAttributes:locationAttribute:
 Main method for rendering subtitle content.
 
(void) - safelyRemoveObserverIfNeeded
 Safely remove observer.
 
(void) - setup:
 Initialize renderer and set parent layer.
 
(void) - setVttHeader:
 Set VTT header information.
 
(void) - showDialogue:atIndex:
 Show subtitle at specified index.
 
(RenderContext *) - updateRenderContext:withSubStr:
 Update rendering context.
 
(void) - updateVideoDisPlay:height:scaleMode:
 Update video display information.
 

Properties

Class constClass
 全局常量类,所有实例共享 Global constant class shared by all instances
 
NSMutableArray * dialogueArr
 管理的字幕对话框对象数组 Array of managed subtitle dialogue objects
 
float mContentsScale
 内容缩放比例 (pixels / contentsScale = points) Content scale ratio (pixels / contentsScale = points)
 
CALayer * mLayer
 字幕渲染的父图层 Parent layer for subtitle rendering
 
float mVideoDisPlayHeightPoint
 视频显示区域高度,单位为点(point) Video display area height in points
 
float mVideoDisPlayWidthPoint
 视频显示区域宽度,单位为点(point) Video display area width in points
 

Detailed Description

VTT subtitle rendering implementation class.

Core rendering engine responsible for subtitle parsing, style application, layout calculation, and display. Supports various features of the WebVTT standard, including styles, positions, regions, etc.

Note
This class can be inherited to implement custom rendering logic

Method Documentation

◆ actualShow:withContext:

- (void) actualShow: (AliVttDialogueObj *) dialogueObj
withContext: (RenderContext *) context 

Actually display subtitle.

Parameters
dialogueObjSubtitle dialogue object
contextRendering context
Note
Sets final frame and displays layer

◆ applyBackgroundColorStyle:contentAttribute:

- (void) applyBackgroundColorStyle: (AliVttDialogueObj *) dialogueObj
contentAttribute: (VttContentAttribute *) contentAttribute 

Apply background color style.

Parameters
dialogueObjSubtitle dialogue object
contentAttributeContent attribute

◆ applyColorStyle:contentAttribute:

- (void) applyColorStyle: (NSMutableDictionary *) attrs
contentAttribute: (VttContentAttribute *) contentAttribute 

Apply text color style.

Parameters
attrsAttributes dictionary
contentAttributeContent attribute

◆ applyDecorationStyle:contentAttribute:

- (void) applyDecorationStyle: (NSMutableDictionary *) attrs
contentAttribute: (VttContentAttribute *) contentAttribute 

Apply text decoration styles (underline, strikethrough, etc.)

Parameters
attrsAttributes dictionary
contentAttributeContent attribute

◆ applyFontStyle:contentAttribute:context:

- (void) applyFontStyle: (NSMutableDictionary *) attrs
contentAttribute: (VttContentAttribute *) contentAttribute
context: (RenderContext *) context 

Apply font style.

Parameters
attrsAttributes dictionary
contentAttributeContent attribute
contextRendering context

◆ applyLayerSetting:styleStr:

- (void) applyLayerSetting: (AliVttDialogueObj *) dialogueObj
styleStr: (NSAttributedString *) styleStr 

Apply layer settings.

Parameters
dialogueObjSubtitle dialogue object
styleStrStyled text
Note
Sets alignment, wrapping and other CATextLayer properties

◆ applyStrokeAndShadow:contentAttribute:context:

- (void) applyStrokeAndShadow: (NSMutableDictionary *) attrs
contentAttribute: (VttContentAttribute *) contentAttribute
context: (RenderContext *) context 

Apply stroke and shadow effects.

Parameters
attrsAttributes dictionary
contentAttributeContent attribute
contextRendering context

◆ calculateMaxTextWidth

- (CGFloat) calculateMaxTextWidth

Calculate maximum text width.

Returns
Maximum text width value

◆ clear

- (void) clear

Clear all subtitle display content.

Note
Remove all layers and clear dialogue array

◆ containsFullWidthCharacters:

- (BOOL) containsFullWidthCharacters: (NSString *) string

Detect if string contains full-width characters.

Parameters
stringString to be detected
Returns
Returns YES if contains full-width characters, otherwise NO
Note
Full-width characters include Chinese, Japanese, Korean, etc.

◆ containsUpperGlyphCharacters:

- (BOOL) containsUpperGlyphCharacters: (NSString *) string

Detect if string contains superscript characters.

Parameters
stringString to be detected
Returns
Returns YES if contains superscript characters, otherwise NO
Note
Mainly detects complex characters with superscripts and subscripts like Thai

◆ createStyledText:dialogueObj:withContext:

- (NSAttributedString *) createStyledText: (NSArray< VttContentAttribute * > *) contentAttributes
dialogueObj: (AliVttDialogueObj *) dialogueObj
withContext: (RenderContext **) context 

Create styled attributed text.

Parameters
contentAttributesContent attributes array
dialogueObjSubtitle dialogue object
contextDouble pointer to rendering context
Returns
Created NSAttributedString object
Note
Also sets background color and calculates text size

◆ createStyledTextSegment:context:

- (NSAttributedString *) createStyledTextSegment: (VttContentAttribute *) contentAttribute
context: (RenderContext **) context 

Create styled string for single text segment.

Parameters
contentAttributeContent attribute
contextDouble pointer to rendering context
Returns
Styled text segment

◆ customizeAttribuets:locationAttribute:

- (void) customizeAttribuets: (NSMutableArray< VttContentAttribute * > *) contentAttributes
locationAttribute: (VttLocationAttribute *) locationAttribute 

Customize content attributes and location information (for subclass override)

Parameters
contentAttributesArray of content attribute objects
locationAttributeLocation attribute object
Note
Default implementation is empty, subclasses can override to implement special attribute processing logic, such as batch setting text styles or handling rich text behaviors

◆ customizeFont:contentAttribute:contentText:

- (UIFont *) customizeFont: (UIFont *) originalFont
contentAttribute: (VttContentAttribute *) contentAttribute
contentText: (NSString *) text 

Customize font (for subclass override)

Parameters
originalFontOriginal font
contentAttributeContent attribute
textText content
Returns
Customized font, default returns original font
Note
Subclasses can override to apply special font processing logic

◆ customizeParagraphStyle:withFont:contentText:

- (void) customizeParagraphStyle: (NSMutableParagraphStyle *) paragraphStyle
withFont: (UIFont *) font
contentText: (NSString *) text 

Customize paragraph style (for subclass override)

Parameters
paragraphStyleParagraph style object
fontFont object
textText content
Note
Default implementation is empty, subclasses can override to customize line spacing and other properties

◆ findDialogueObjByIdx:

- (AliVttDialogueObj *) findDialogueObjByIdx: (NSInteger) index

Find subtitle dialogue object by index.

Parameters
indexSubtitle index
Returns
Found dialogue object, returns nil if not found

◆ findIdleDialogueObj

- (AliVttDialogueObj *) findIdleDialogueObj

Find idle subtitle dialogue object.

Returns
Idle dialogue object, returns nil if not found
Note
Idle means the object whose layer is in hidden state

◆ generateFontWithName:fontSize:isBold:isItalic:

- (UIFont *) generateFontWithName: (NSString *) fontName
fontSize: (CGFloat) fontSize
isBold: (BOOL) isBold
isItalic: (BOOL) isItalic 

Generate font with specified style.

Parameters
fontNameFont name
fontSizeFont size
isBoldWhether bold
isItalicWhether italic
Returns
Generated UIFont object

◆ getActualTextPositions:withContext:

- (void) getActualTextPositions: (VttLocationAttribute *) locationAttribute
withContext: (RenderContext *) context 

Calculate subtitle display position.

Parameters
locationAttributeLocation attribute
contextRendering context
Note
Calculates final x,y coordinates based on location attributes and default rules

◆ getActualTextSize:dialogue:withContext:

- (void) getActualTextSize: (NSAttributedString *) styleStr
dialogue: (AliVttDialogueObj *) dialogueObj
withContext: (RenderContext *) context 

Calculate actual text size.

Parameters
styleStrStyled text string
dialogueObjSubtitle dialogue object
contextRendering context

◆ getColorFromValue:

- (UIColor *) getColorFromValue: (NSInteger) value

Create UIColor object from integer value.

Parameters
valueColor value in ARGB format
Returns
Corresponding UIColor object

◆ getParentViewSize:h:

- (void) getParentViewSize: (CGFloat *) w
h: (CGFloat *) h 

Get parent view size.

Parameters
wWidth pointer for returning width value
hHeight pointer for returning height value

◆ getSizeFromStr:withMaxtextWidth:

- (CGSize) getSizeFromStr: (NSMutableAttributedString *) attrStr
withMaxtextWidth: (CGFloat) maxTextWidth 

Calculate display size of attributed text.

Parameters
attrStrAttributed text string
maxTextWidthMaximum text width
Returns
Calculated text size

◆ getVttHeader

- (nullable AliWebVttHeader *) getVttHeader

Get VTT header information.

Returns
AliWebVttHeader object, returns nil if not set

◆ hideDialogue:atIndex:

- (void) hideDialogue: (NSString *) data
atIndex: (int) index 

Hide subtitle at specified index.

Parameters
dataSubtitle data string
indexSubtitle index

◆ initialDialogueObj:index:

- (void) initialDialogueObj: (AliVttDialogueObj **) obj
index: (NSUInteger) index 

Initialize subtitle dialogue object.

Parameters
objDouble pointer to dialogue object for returning created or reused object
indexSubtitle index
Note
Creates new object if passed object is nil; otherwise reuses existing object

◆ maybeApplyDefaultPosition:withContext:

- (CGPoint) maybeApplyDefaultPosition: (CGPoint) locationPoint
withContext: (RenderContext *) context 

Apply default position rules.

Parameters
locationPointCoordinate point calculated from location attributes
contextRendering context
Returns
Final coordinate point after applying default rules

◆ maybeForcebeCenter:withContext:

- (CGFloat) maybeForcebeCenter: (CGFloat) x
withContext: (RenderContext *) context 

Force center alignment (when position is out of range)

Parameters
xX coordinate
contextRendering context
Returns
Adjusted X coordinate

◆ maybeUpperThanBase:withContext:

- (CGFloat) maybeUpperThanBase: (CGFloat) y
withContext: (RenderContext *) context 

Ensure position is above baseline.

Parameters
yY coordinate
contextRendering context
Returns
Adjusted Y coordinate

◆ prepareRenderContext

- (RenderContext *) prepareRenderContext

Prepare rendering context.

Returns
Initialized rendering context object
Note
Calculates basic information like parent view, video display area, etc.

◆ processAttributePosition:withContext:

- (CGPoint) processAttributePosition: (VttLocationAttribute *) locationAttribute
withContext: (RenderContext *) context 

Process location attributes and calculate base coordinates.

Parameters
locationAttributeLocation attribute
contextRendering context
Returns
Calculated coordinate point

◆ processXPositon:withContext:

- (CGFloat) processXPositon: (VttLocationAttribute *) locationAttribute
withContext: (RenderContext *) context 

Process X direction position.

Parameters
locationAttributeLocation attribute
contextRendering context
Returns
X coordinate value

◆ processYPosition:withContext:

- (CGFloat) processYPosition: (VttLocationAttribute *) locationAttribute
withContext: (RenderContext *) context 

Process Y direction position.

Parameters
locationAttributeLocation attribute
contextRendering context
Returns
Y coordinate value

◆ renderSubtitleContent:contentAttributes:locationAttribute:

- (void) renderSubtitleContent: (AliVttDialogueObj *) dialogueObj
contentAttributes: (NSArray< VttContentAttribute * > *) contentAttributes
locationAttribute: (VttLocationAttribute *) locationAttribute 

Main method for rendering subtitle content.

Parameters
dialogueObjSubtitle dialogue object
contentAttributesContent attributes array
locationAttributeLocation attribute
Note
This is the entry method of rendering pipeline, coordinating various rendering steps

◆ safelyRemoveObserverIfNeeded

- (void) safelyRemoveObserverIfNeeded

Safely remove observer.

Note
Called during dealloc to avoid observer-related crashes

◆ setup:

- (void) setup: (CALayer *) view

Initialize renderer and set parent layer.

Parameters
viewCALayer object for displaying subtitles
Note
This method automatically switches to main thread for UI operation thread safety

◆ setVttHeader:

- (void) setVttHeader: (NSString *) header

Set VTT header information.

Parameters
headerVTT header string containing style and region definitions

◆ showDialogue:atIndex:

- (void) showDialogue: (NSString *) data
atIndex: (int) index 

Show subtitle at specified index.

Parameters
dataSubtitle data string
indexSubtitle index

◆ updateRenderContext:withSubStr:

- (RenderContext *) updateRenderContext: (RenderContext *) context
withSubStr: (NSAttributedString *) subAttributedString 

Update rendering context.

Parameters
contextRendering context
subAttributedStringSub attributed string
Returns
Updated rendering context

◆ updateVideoDisPlay:height:scaleMode:

- (void) updateVideoDisPlay: (int) videoWidth
height: (int) videoHeight
scaleMode: (AVPScalingMode) mode 

Update video display information.

Parameters
videoWidthVideo width in pixels
videoHeightVideo height in pixels
modeVideo scaling mode

Property Documentation

◆ constClass

- (Class) constClass
readwritenonatomicassign

全局常量类,所有实例共享 Global constant class shared by all instances

◆ dialogueArr

- (NSMutableArray*) dialogueArr
readwritenonatomicstrong

管理的字幕对话框对象数组 Array of managed subtitle dialogue objects

◆ mContentsScale

- (float) mContentsScale
readwritenonatomicassign

内容缩放比例 (pixels / contentsScale = points) Content scale ratio (pixels / contentsScale = points)

◆ mLayer

- (CALayer*) mLayer
readwritenonatomicstrong

字幕渲染的父图层 Parent layer for subtitle rendering

◆ mVideoDisPlayHeightPoint

- (float) mVideoDisPlayHeightPoint
readwritenonatomicassign

视频显示区域高度,单位为点(point) Video display area height in points

◆ mVideoDisPlayWidthPoint

- (float) mVideoDisPlayWidthPoint
readwritenonatomicassign

视频显示区域宽度,单位为点(point) Video display area width in points


The documentation for this class was generated from the following file: