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

VTT字幕渲染实现类 More...

#include "AliVttSubtitleView.h"

Inheritance diagram for AliVttRenderImpl:

Instance Methods

(void) - actualShow:withContext:
 实际显示字幕
 
(void) - applyBackgroundColorStyle:contentAttribute:
 应用背景颜色样式
 
(void) - applyColorStyle:contentAttribute:
 应用文本颜色样式
 
(void) - applyDecorationStyle:contentAttribute:
 应用文本装饰样式(下划线、删除线等)
 
(void) - applyFontStyle:contentAttribute:context:
 应用字体样式
 
(void) - applyLayerSetting:styleStr:
 应用图层设置
 
(void) - applyStrokeAndShadow:contentAttribute:context:
 应用描边和阴影效果
 
(CGFloat) - calculateMaxTextWidth
 计算最大文本宽度
 
(void) - clear
 清除所有字幕显示内容
 
(BOOL) - containsFullWidthCharacters:
 检测字符串是否包含全宽字符
 
(BOOL) - containsUpperGlyphCharacters:
 检测字符串是否包含上标字符
 
(NSAttributedString *) - createStyledText:dialogueObj:withContext:
 创建样式化的富文本
 
(NSAttributedString *) - createStyledTextSegment:context:
 创建单个文本段的样式化字符串
 
(void) - customizeAttribuets:locationAttribute:
 自定义内容属性及位置信息(供子类重写)
 
(UIFont *) - customizeFont:contentAttribute:contentText:
 自定义字体(供子类重写)
 
(void) - customizeParagraphStyle:withFont:contentText:
 自定义段落样式(供子类重写)
 
(AliVttDialogueObj *) - findDialogueObjByIdx:
 根据索引查找字幕对话框对象
 
(AliVttDialogueObj *) - findIdleDialogueObj
 查找空闲的字幕对话框对象
 
(UIFont *) - generateFontWithName:fontSize:isBold:isItalic:
 生成指定样式的字体
 
(void) - getActualTextPositions:withContext:
 计算字幕显示位置
 
(void) - getActualTextSize:dialogue:withContext:
 计算实际文本尺寸
 
(UIColor *) - getColorFromValue:
 从整数值创建UIColor对象
 
(void) - getParentViewSize:h:
 获取父视图尺寸
 
(CGSize) - getSizeFromStr:withMaxtextWidth:
 计算富文本的显示尺寸
 
(nullable AliWebVttHeader *) - getVttHeader
 获取VTT头部信息
 
(void) - hideDialogue:atIndex:
 隐藏指定索引的字幕
 
(void) - initialDialogueObj:index:
 初始化字幕对话框对象
 
(CGPoint) - maybeApplyDefaultPosition:withContext:
 应用默认位置规则
 
(CGFloat) - maybeForcebeCenter:withContext:
 强制居中对齐(当位置超出范围时)
 
(CGFloat) - maybeUpperThanBase:withContext:
 确保位置在基准线之上
 
(RenderContext *) - prepareRenderContext
 准备渲染上下文
 
(CGPoint) - processAttributePosition:withContext:
 处理位置属性,计算基础坐标
 
(CGFloat) - processXPositon:withContext:
 处理X方向位置
 
(CGFloat) - processYPosition:withContext:
 处理Y方向位置
 
(void) - renderSubtitleContent:contentAttributes:locationAttribute:
 渲染字幕内容的主要方法
 
(void) - safelyRemoveObserverIfNeeded
 安全移除观察者
 
(void) - setup:
 初始化渲染器,设置父图层
 
(void) - setVttHeader:
 设置VTT头部信息
 
(void) - showDialogue:atIndex:
 显示指定索引的字幕
 
(RenderContext *) - updateRenderContext:withSubStr:
 更新渲染上下文
 
(void) - updateVideoDisPlay:height:scaleMode:
 更新视频显示信息
 

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字幕渲染实现类

核心渲染引擎,负责字幕的解析、样式应用、布局计算和显示。 支持WebVTT标准的各种特性,包括样式、位置、区域等。

Note
该类可以被继承以实现自定义的渲染逻辑

Method Documentation

◆ actualShow:withContext:

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

实际显示字幕

Parameters
dialogueObj字幕对话框对象
context渲染上下文
Note
设置最终的frame并显示图层

◆ applyBackgroundColorStyle:contentAttribute:

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

应用背景颜色样式

Parameters
dialogueObj字幕对话框对象
contentAttribute内容属性

◆ applyColorStyle:contentAttribute:

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

应用文本颜色样式

Parameters
attrs属性字典
contentAttribute内容属性

◆ applyDecorationStyle:contentAttribute:

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

应用文本装饰样式(下划线、删除线等)

Parameters
attrs属性字典
contentAttribute内容属性

◆ applyFontStyle:contentAttribute:context:

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

应用字体样式

Parameters
attrs属性字典
contentAttribute内容属性
context渲染上下文

◆ applyLayerSetting:styleStr:

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

应用图层设置

Parameters
dialogueObj字幕对话框对象
styleStr样式化文本
Note
设置对齐方式、换行等CATextLayer属性

◆ applyStrokeAndShadow:contentAttribute:context:

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

应用描边和阴影效果

Parameters
attrs属性字典
contentAttribute内容属性
context渲染上下文

◆ calculateMaxTextWidth

- (CGFloat) calculateMaxTextWidth

计算最大文本宽度

Returns
最大文本宽度值

◆ clear

- (void) clear

清除所有字幕显示内容

Note
移除所有图层并清空对话框数组

◆ containsFullWidthCharacters:

- (BOOL) containsFullWidthCharacters: (NSString *) string

检测字符串是否包含全宽字符

Parameters
string待检测的字符串
Returns
包含全宽字符返回YES,否则返回NO
Note
全宽字符包括中文、日文、韩文等

◆ containsUpperGlyphCharacters:

- (BOOL) containsUpperGlyphCharacters: (NSString *) string

检测字符串是否包含上标字符

Parameters
string待检测的字符串
Returns
包含上标字符返回YES,否则返回NO
Note
主要检测泰文等具有上下标的复杂字符

◆ createStyledText:dialogueObj:withContext:

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

创建样式化的富文本

Parameters
contentAttributes内容属性数组
dialogueObj字幕对话框对象
context渲染上下文的双重指针
Returns
创建的NSAttributedString对象
Note
同时会设置背景颜色和计算文本尺寸

◆ createStyledTextSegment:context:

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

创建单个文本段的样式化字符串

Parameters
contentAttribute内容属性
context渲染上下文的双重指针
Returns
样式化的文本段

◆ customizeAttribuets:locationAttribute:

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

自定义内容属性及位置信息(供子类重写)

Parameters
contentAttributes内容属性数组
locationAttribute位置属性对象
Note
默认实现为空,子类可重写以实现特殊的属性处理逻辑,例如批量设置文本样式、处理丰富文本的行为等

◆ customizeFont:contentAttribute:contentText:

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

自定义字体(供子类重写)

Parameters
originalFont原始字体
contentAttribute内容属性
text文本内容
Returns
自定义后的字体,默认返回原始字体
Note
子类可重写以应用特殊的字体处理逻辑

◆ customizeParagraphStyle:withFont:contentText:

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

自定义段落样式(供子类重写)

Parameters
paragraphStyle段落样式对象
font字体对象
text文本内容
Note
默认实现为空,子类可重写以自定义行间距等属性

◆ findDialogueObjByIdx:

- (AliVttDialogueObj *) findDialogueObjByIdx: (NSInteger) index

根据索引查找字幕对话框对象

Parameters
index字幕索引
Returns
找到的对话框对象,未找到返回nil

◆ findIdleDialogueObj

- (AliVttDialogueObj *) findIdleDialogueObj

查找空闲的字幕对话框对象

Returns
空闲的对话框对象,未找到返回nil
Note
空闲是指图层处于隐藏状态的对象

◆ generateFontWithName:fontSize:isBold:isItalic:

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

生成指定样式的字体

Parameters
fontName字体名称
fontSize字体大小
isBold是否粗体
isItalic是否斜体
Returns
生成的UIFont对象

◆ getActualTextPositions:withContext:

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

计算字幕显示位置

Parameters
locationAttribute位置属性
context渲染上下文
Note
根据位置属性和默认规则计算最终的x,y坐标

◆ getActualTextSize:dialogue:withContext:

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

计算实际文本尺寸

Parameters
styleStr样式化的文本字符串
dialogueObj字幕对话框对象
context渲染上下文

◆ getColorFromValue:

- (UIColor *) getColorFromValue: (NSInteger) value

从整数值创建UIColor对象

Parameters
valueARGB格式的颜色值
Returns
对应的UIColor对象

◆ getParentViewSize:h:

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

获取父视图尺寸

Parameters
w宽度指针,用于返回宽度值
h高度指针,用于返回高度值

◆ getSizeFromStr:withMaxtextWidth:

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

计算富文本的显示尺寸

Parameters
attrStr富文本字符串
maxTextWidth最大文本宽度
Returns
计算得到的文本尺寸

◆ getVttHeader

- (nullable AliWebVttHeader *) getVttHeader

获取VTT头部信息

Returns
AliWebVttHeader对象,如果未设置则返回nil

◆ hideDialogue:atIndex:

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

隐藏指定索引的字幕

Parameters
data字幕数据字符串
index字幕索引

◆ initialDialogueObj:index:

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

初始化字幕对话框对象

Parameters
obj字幕对话框对象的双重指针,用于返回创建或复用的对象
index字幕索引
Note
如果传入的对象为空,会创建新对象;否则复用现有对象

◆ maybeApplyDefaultPosition:withContext:

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

应用默认位置规则

Parameters
locationPoint位置属性计算的坐标点
context渲染上下文
Returns
应用默认规则后的最终坐标点

◆ maybeForcebeCenter:withContext:

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

强制居中对齐(当位置超出范围时)

Parameters
xX坐标
context渲染上下文
Returns
调整后的X坐标

◆ maybeUpperThanBase:withContext:

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

确保位置在基准线之上

Parameters
yY坐标
context渲染上下文
Returns
调整后的Y坐标

◆ prepareRenderContext

- (RenderContext *) prepareRenderContext

准备渲染上下文

Returns
初始化的渲染上下文对象
Note
计算父视图、视频显示区域等基础信息

◆ processAttributePosition:withContext:

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

处理位置属性,计算基础坐标

Parameters
locationAttribute位置属性
context渲染上下文
Returns
计算得到的坐标点

◆ processXPositon:withContext:

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

处理X方向位置

Parameters
locationAttribute位置属性
context渲染上下文
Returns
X坐标值

◆ processYPosition:withContext:

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

处理Y方向位置

Parameters
locationAttribute位置属性
context渲染上下文
Returns
Y坐标值

◆ renderSubtitleContent:contentAttributes:locationAttribute:

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

渲染字幕内容的主要方法

Parameters
dialogueObj字幕对话框对象
contentAttributes内容属性数组
locationAttribute位置属性
Note
这是渲染管线的入口方法,协调各个渲染步骤

◆ safelyRemoveObserverIfNeeded

- (void) safelyRemoveObserverIfNeeded

安全移除观察者

Note
在dealloc时调用,避免观察者相关的崩溃

◆ setup:

- (void) setup: (CALayer *) view

初始化渲染器,设置父图层

Parameters
view用于显示字幕的CALayer对象
Note
该方法会自动切换到主线程执行,确保UI操作的线程安全

◆ setVttHeader:

- (void) setVttHeader: (NSString *) header

设置VTT头部信息

Parameters
headerVTT头部字符串,包含样式和区域定义

◆ showDialogue:atIndex:

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

显示指定索引的字幕

Parameters
data字幕数据字符串
index字幕索引

◆ updateRenderContext:withSubStr:

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

更新渲染上下文

Parameters
context渲染上下文
subAttributedString子文本字符串
Returns
更新后的渲染上下文

◆ updateVideoDisPlay:height:scaleMode:

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

更新视频显示信息

Parameters
videoWidth视频宽度,单位为像素
videoHeight视频高度,单位为像素
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: