Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Android/PlayerProj/animplayer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 28
compileSdkVersion 31

defaultConfig {
minSdkVersion 16
targetSdkVersion 28
versionCode 1
minSdkVersion 31
targetSdkVersion 31
versionCode 31
versionName "1.0"
}

Expand Down
9 changes: 5 additions & 4 deletions Android/PlayerProj/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 28
compileSdkVersion 31
defaultConfig {
applicationId "com.tencent.qgame.playerproj"
minSdkVersion 16
targetSdkVersion 28
minSdkVersion 31
targetSdkVersion 31
versionCode 1
versionName "1.0"
}
Expand All @@ -26,5 +26,6 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation project(":animplayer")
// implementation project(":animplayer")
implementation 'io.github.tencent:vap:2.0.16'
}
3 changes: 2 additions & 1 deletion Android/PlayerProj/bintrayv1.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ if (project.hasProperty("android")) { // Android libraries
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}
} else { // Java libraries
task sourcesJar(type: Jar, dependsOn: classes) {
task sourcesJar(type: Jar
, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
Expand Down
2 changes: 1 addition & 1 deletion Android/PlayerProj/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.5.20'
repositories {
google()
// jcenter()
Expand Down
3 changes: 2 additions & 1 deletion Android/PlayerProj/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Tue Apr 29 17:17:27 CST 2025
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
12 changes: 8 additions & 4 deletions iOS/QGVAPlayer/QGVAPlayer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -761,12 +761,13 @@
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Automatic;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = 6W55574XBS;
DEVELOPMENT_TEAM = YQ2BBNYL5U;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = QGVAPlayer/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 12;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -785,12 +786,13 @@
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Automatic;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = 6W55574XBS;
DEVELOPMENT_TEAM = YQ2BBNYL5U;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = QGVAPlayer/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 12;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -807,8 +809,9 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 6W55574XBS;
DEVELOPMENT_TEAM = YQ2BBNYL5U;
INFOPLIST_FILE = QGVAPlayerTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -824,8 +827,9 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 6W55574XBS;
DEVELOPMENT_TEAM = YQ2BBNYL5U;
INFOPLIST_FILE = QGVAPlayerTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
@optional
- (NSString *)vap_contentForTag:(NSString *)tag resource:(QGVAPSourceInfo *)info; //替换配置中的资源占位符(不处理直接返回tag)
- (void)vap_loadImageWithURL:(NSString *)urlStr context:(NSDictionary *)context completion:(VAPImageCompletionBlock)completionBlock;

/// 自定义字体文字加载
- (UIImage *)loadVapContent:(NSString *)content context:(NSDictionary *)context;
@end

@interface QGVAPConfigManager : NSObject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,17 @@ - (void)loadConfigResources {

NSString *tagContent = resource.contentTagValue;
if ([resource.type isEqualToString:kQGAGAttachmentSourceTypeText] && [resource.loadType isEqualToString:QGAGAttachmentSourceLoadTypeLocal]) {
resource.sourceImage = [QGVAPTextureLoader drawingImageForText:tagContent color:resource.color size:resource.size bold:[resource.style isEqualToString:kQGAGAttachmentSourceStyleBoldText]];
NSDictionary *context = @{@"resource":resource};
if ([self.delegate respondsToSelector:@selector(loadVapContent:context:)]) {
UIImage * img = [self.delegate loadVapContent:tagContent context:context];
if (img) {
resource.sourceImage = img;
} else {
resource.sourceImage = [QGVAPTextureLoader drawingImageForText:tagContent color:resource.color size:resource.size bold:[resource.style isEqualToString:kQGAGAttachmentSourceStyleBoldText]];
}
} else {
resource.sourceImage = [QGVAPTextureLoader drawingImageForText:tagContent color:resource.color size:resource.size bold:[resource.style isEqualToString:kQGAGAttachmentSourceStyleBoldText]];
}
}

if ([resource.type isEqualToString:kQGAGAttachmentSourceTypeImg] && [resource.loadType isEqualToString:QGAGAttachmentSourceLoadTypeNet]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@

#import <UIKit/UIKit.h>
#import <Metal/Metal.h>

typedef UIFont * (^LoadCustomFontBlock)(CGFloat,BOOL);
@interface QGVAPTextureLoader : NSObject


+ (id<MTLBuffer>)loadVapColorFillBufferWith:(UIColor *)color device:(id<MTLDevice>)device;

+ (id<MTLTexture>)loadTextureWithImage:(UIImage *)image device:(id<MTLDevice>)device;
Expand All @@ -28,4 +29,7 @@

+ (UIFont *)getAppropriateFontWith:(NSString *)text rect:(CGRect)fitFrame designedSize:(CGFloat)designedFontSize bold:(BOOL)isBold textSize:(CGSize *)textSize;

+(void)loadCustomFont: (nullable LoadCustomFontBlock ) fontBlock;

+ (nullable UIImage *)drawingCustomImageForText:(NSString *)textStr color:(UIColor *)color size:(CGSize)size bold:(BOOL)bold fontBlock: (LoadCustomFontBlock)fontBlock;
@end
88 changes: 86 additions & 2 deletions iOS/QGVAPlayer/QGVAPlayer/Classes/Models/QGVAPTextureLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#import "QGVAPLogger.h"
#import "UIDevice+VAPUtil.h"


static LoadCustomFontBlock staticFontBlock;

@implementation QGVAPTextureLoader

#if TARGET_OS_SIMULATOR//模拟器
Expand Down Expand Up @@ -58,6 +61,11 @@ + (UIFont *)getAppropriateFontWith:(NSString *)text rect:(CGRect)fitFrame design
}
return [self cg_loadTextureWithImage:image device:device];
}
+(void)loadCustomFont: (nullable LoadCustomFontBlock) fontBlock {
staticFontBlock = fontBlock;
}



+ (UIImage *)drawingImageForText:(NSString *)textStr color:(UIColor *)color size:(CGSize)size bold:(BOOL)bold {

Expand Down Expand Up @@ -157,7 +165,7 @@ + (UIImage *)drawingImageForText:(NSString *)textStr color:(UIColor *)color size
//根据指定的字符内容和容器大小计算合适的字体
+ (UIFont *)getAppropriateFontWith:(NSString *)text rect:(CGRect)fitFrame designedSize:(CGFloat)designedFontSize bold:(BOOL)isBold textSize:(CGSize *)textSize {

UIFont *designedFont = isBold? [UIFont boldSystemFontOfSize:designedFontSize] : [UIFont systemFontOfSize:designedFontSize];
UIFont *designedFont = [self judgeFontWithFontSize:designedFontSize isBold:isBold];
if (text.length == 0 || CGRectEqualToRect(CGRectZero, fitFrame) || !designedFont) {
*textSize = fitFrame.size;
return designedFont ;
Expand All @@ -168,7 +176,7 @@ + (UIFont *)getAppropriateFontWith:(NSString *)text rect:(CGRect)fitFrame design
while (stringSize.width > fitFrame.size.width && fontSize > 2.0 && remainExcuteCount > 0) {
fontSize *= 0.9;
remainExcuteCount -= 1;
designedFont = isBold? [UIFont boldSystemFontOfSize:fontSize] : [UIFont systemFontOfSize:fontSize];
designedFont = [self judgeFontWithFontSize:fontSize isBold:isBold];
stringSize = [text sizeWithAttributes:@{NSFontAttributeName:designedFont}];
}
if (remainExcuteCount < 1 || fontSize < 5.0) {
Expand All @@ -178,6 +186,82 @@ + (UIFont *)getAppropriateFontWith:(NSString *)text rect:(CGRect)fitFrame design
return designedFont;
}

+(UIFont *)judgeFontWithFontSize: (CGFloat)fontSize isBold: (BOOL)isBold {
if (staticFontBlock) {
UIFont * designedFont = staticFontBlock(fontSize,isBold);
if (designedFont) {
return designedFont;
}
}
UIFont *designedFont = isBold? [UIFont boldSystemFontOfSize:fontSize] : [UIFont systemFontOfSize:fontSize];
return designedFont;
}


+ (UIImage *)drawingCustomImageForText:(NSString *)textStr color:(UIColor *)color size:(CGSize)size bold:(BOOL)bold fontBlock: (LoadCustomFontBlock)fontBlock {

if (textStr.length == 0) {
VAP_Error(kQGVAPModuleCommon, @"draw text resource fail cuz text is nil !!");
return nil;
}
if (!color) {
color = [UIColor blackColor];
}
CGRect rect = CGRectMake(0, 0, size.width/2.0, size.height/2.0);
CGSize textSize = CGSizeZero;
UIFont *font = [QGVAPTextureLoader getAppropriateCustomFontWith:textStr rect:rect designedSize:rect.size.height*0.8 bold:bold textSize:&textSize fontBlock: fontBlock];
if (!font) {
VAP_Error(kQGVAPModuleCommon, @"draw text resource:%@ fail cuz font is nil !!", textStr);
return nil;
}
NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
paragraphStyle.alignment = NSTextAlignmentCenter;
paragraphStyle.lineBreakMode = NSLineBreakByTruncatingTail;
NSDictionary *attr = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:paragraphStyle, NSForegroundColorAttributeName:color};
UIGraphicsBeginImageContextWithOptions(rect.size, NO, [UIScreen mainScreen].scale);
rect.origin.y = (rect.size.height - font.lineHeight)/2.0;
[textStr drawWithRect:rect options:NSStringDrawingUsesLineFragmentOrigin attributes:attr context:nil];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
if (!image) {
VAP_Error(kQGVAPModuleCommon, @"draw text resource:%@ fail cuz UIGraphics fail.", textStr);
return nil;
}
return image;
}
//根据指定的字符内容和容器大小计算合适的字体
+ (UIFont *)getAppropriateCustomFontWith:(NSString *)text rect:(CGRect)fitFrame designedSize:(CGFloat)designedFontSize bold:(BOOL)isBold textSize:(CGSize *)textSize fontBlock: (LoadCustomFontBlock)fontBlock {

UIFont *designedFont = [self judgeCustomFontWithFontSize:designedFontSize isBold:isBold fontBlock:fontBlock];
if (text.length == 0 || CGRectEqualToRect(CGRectZero, fitFrame) || !designedFont) {
*textSize = fitFrame.size;
return designedFont ;
}
CGSize stringSize = [text sizeWithAttributes:@{NSFontAttributeName:designedFont}];
CGFloat fontSize = designedFontSize;
NSInteger remainExcuteCount = 100;
while (stringSize.width > fitFrame.size.width && fontSize > 2.0 && remainExcuteCount > 0) {
fontSize *= 0.9;
remainExcuteCount -= 1;
designedFont = [self judgeCustomFontWithFontSize:fontSize isBold:isBold fontBlock:fontBlock];
stringSize = [text sizeWithAttributes:@{NSFontAttributeName:designedFont}];
}
if (remainExcuteCount < 1 || fontSize < 5.0) {
VAP_Event(kQGVAPModuleCommon, @"data exception content:%@ rect:%@ designedSize:%@ isBold:%@", text, [NSValue valueWithCGRect:fitFrame], @(designedFontSize), @(isBold));
}
*textSize = stringSize;
return designedFont;
}
+(UIFont *)judgeCustomFontWithFontSize: (CGFloat)fontSize isBold: (BOOL)isBold fontBlock: (LoadCustomFontBlock)fontBlock {
if (fontBlock) {
UIFont * designedFont = fontBlock(fontSize,isBold);
if (designedFont) {
return designedFont;
}
}
UIFont *designedFont = isBold? [UIFont boldSystemFontOfSize:fontSize] : [UIFont systemFontOfSize:fontSize];
return designedFont;
}
#endif

@end
5 changes: 4 additions & 1 deletion iOS/QGVAPlayer/QGVAPlayer/Classes/QGVAPWrapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ typedef NS_ENUM(NSUInteger, QGVAPWrapViewContentMode) {
QGVAPWrapViewContentModeScaleToFill,
QGVAPWrapViewContentModeAspectFit,
QGVAPWrapViewContentModeAspectFill,
QGVAPWrapViewContentModeTop,
QGVAPWrapViewContentModeBottom,
};

@protocol VAPWrapViewDelegate <NSObject>
Expand All @@ -40,7 +42,8 @@ typedef NS_ENUM(NSUInteger, QGVAPWrapViewContentMode) {
//vap APIs
- (NSString *)vapWrapview_contentForVapTag:(NSString *)tag resource:(QGVAPSourceInfo *)info; //替换配置中的资源占位符(不处理直接返回tag)
- (void)vapWrapView_loadVapImageWithURL:(NSString *)urlStr context:(NSDictionary *)context completion:(VAPImageCompletionBlock)completionBlock; //由于组件内不包含网络图片加载的模块,因此需要外部支持图片加载。

/// 自定义字体文字加载
- (nullable UIImage * )vapWrapView_loadVapContent:(NSString *)content context:(NSDictionary *)context;
@end

/*
Expand Down
Loading