Set the fontSize in the tx3g styles.

This commit is contained in:
Damiano Galassi committed 2018-01-03 10:47:44 +01:00
1 parent 99b331ead6
commit 2a3772f618
3 files changed
+19 -16

No files matched your search

+1 -3
View File
@@ -112,9 +112,7 @@
[ss setFinished:YES]; [ss setFinished:YES];
for (MP42SubtitleTrack *track in self.inputTracks) { for (MP42SubtitleTrack *track in self.inputTracks) {
CGSize trackSize; CGSize trackSize = CGSizeMake(track.trackWidth, track.trackHeight);
trackSize.width = track.trackWidth;
trackSize.height = track.trackHeight;
MP42SampleBuffer *sample; MP42SampleBuffer *sample;
while (!ss.isEmpty && !self.isCancelled) { while (!ss.isEmpty && !self.isCancelled) {
+14 -12
View File
@@ -806,7 +806,7 @@ int LoadSMIFromURL(NSURL *url, MP42SubSerializer *ss, int subCount)
return 1; return 1;
} }
u_int8_t* createStyleRecord(u_int16_t startChar, u_int16_t endChar, u_int16_t fontID, u_int8_t flags, rgba_color color, u_int8_t* style) u_int8_t * createStyleRecord(u_int16_t startChar, u_int16_t endChar, u_int16_t fontID, u_int8_t flags, rgba_color color, u_int8_t* style, u_int8_t fontSize)
{ {
style[0] = (startChar >> 8) & 0xff; // startChar style[0] = (startChar >> 8) & 0xff; // startChar
style[1] = startChar & 0xff; style[1] = startChar & 0xff;
@@ -814,12 +814,12 @@ u_int8_t* createStyleRecord(u_int16_t startChar, u_int16_t endChar, u_int16_t fo
style[3] = endChar & 0xff; style[3] = endChar & 0xff;
style[4] = (fontID >> 8) & 0xff; // font-ID style[4] = (fontID >> 8) & 0xff; // font-ID
style[5] = fontID & 0xff; style[5] = fontID & 0xff;
style[6] = flags; // face-style-flags: 1 bold; 2 italic; 4 underline style[6] = flags; // face-style-flags: 1 bold; 2 italic; 4 underline
style[7] = 24; // font-size style[7] = fontSize; // font-size
style[8] = color.r; // r style[8] = color.r; // r
style[9] = color.g; // g style[9] = color.g; // g
style[10] = color.b; // b style[10] = color.b; // b
style[11] = color.a; // a style[11] = color.a; // a
return style; return style;
} }
@@ -837,7 +837,7 @@ size_t closeStyleAtom(u_int16_t styleCount, u_int8_t* styleAtom)
return styleSize; return styleSize;
} }
NSString* createStyleAtomForString(NSString* string, u_int8_t** buffer, size_t *size) NSString * createStyleAtomForString(NSString *string, u_int8_t fontSize, u_int8_t **buffer, size_t *size)
{ {
MP42HtmlParser *parser = [[MP42HtmlParser alloc] initWithString:string]; MP42HtmlParser *parser = [[MP42HtmlParser alloc] initWithString:string];
parser.defaultColor = make_color(255, 255, 255, 255); parser.defaultColor = make_color(255, 255, 255, 255);
@@ -852,7 +852,7 @@ NSString* createStyleAtomForString(NSString* string, u_int8_t** buffer, size_t *
for (MP42Style *style in parser.styles) { for (MP42Style *style in parser.styles) {
u_int8_t styleRecord[12]; u_int8_t styleRecord[12];
createStyleRecord(style.location, style.location + style.length, 1, style.style, style.color, styleRecord); createStyleRecord(style.location, style.location + style.length, 1, style.style, style.color, styleRecord, fontSize);
memcpy(*buffer + 10 + (12 * styleCount), styleRecord, 12); memcpy(*buffer + 10 + (12 * styleCount), styleRecord, 12);
styleCount++; styleCount++;
} }
@@ -912,19 +912,21 @@ MP42SampleBuffer * copySubtitleSample(MP4TrackId subtitleTrackId, NSString *stri
size_t styleSize = 0, sampleSize = 0, stringLength = 0; size_t styleSize = 0, sampleSize = 0, stringLength = 0;
u_int64_t pos = 0; u_int64_t pos = 0;
u_int8_t fontSize = verticalPlacement ? trackSize.height * 0.05 : trackSize.height / 0.15 * 0.05;
string = removeNewLines(string); string = removeNewLines(string);
if (styles) { if (styles) {
string = createStyleAtomForString(string, &styleAtom, &styleSize); string = createStyleAtomForString(string, fontSize, &styleAtom, &styleSize);
} }
stringLength = strlen([string UTF8String]); stringLength = strlen(string.UTF8String);
sampleSize = 2 + (stringLength * sizeof(char)) + styleSize + (forced == 1 ? 8 : 0) + (verticalPlacement == 1 ? 16 : 0); sampleSize = 2 + (stringLength * sizeof(char)) + styleSize + (forced == 1 ? 8 : 0) + (verticalPlacement == 1 ? 16 : 0);
sampleData = malloc(sampleSize); sampleData = malloc(sampleSize);
pos = 2; pos = 2;
if (stringLength) { if (stringLength) {
memcpy(sampleData + pos, [string UTF8String], stringLength); memcpy(sampleData + pos, string.UTF8String, stringLength);
pos += stringLength; pos += stringLength;
} }
+4 -1
View File
@@ -35,6 +35,7 @@
@property (nonatomic, readonly) MP42SSAConverter *converter; @property (nonatomic, readonly) MP42SSAConverter *converter;
@property (nonatomic, readonly) MP4TrackId trackID; @property (nonatomic, readonly) MP4TrackId trackID;
@property (nonatomic, readonly) MP42SubtitleTrack *track;
@property (nonatomic, readonly) _Atomic int32_t finished; @property (nonatomic, readonly) _Atomic int32_t finished;
@@ -105,6 +106,7 @@
} }
_trackID = track.sourceId; _trackID = track.sourceId;
_track = track;
_decoderThread = [[NSThread alloc] initWithTarget:self selector:@selector(TextConverterThreadMainRoutine) object:nil]; _decoderThread = [[NSThread alloc] initWithTarget:self selector:@selector(TextConverterThreadMainRoutine) object:nil];
[_decoderThread setName:@"Text Converter"]; [_decoderThread setName:@"Text Converter"];
@@ -123,6 +125,7 @@
{ {
if (_finished) { if (_finished) {
if (!_ss.isEmpty) { if (!_ss.isEmpty) {
CGSize trackSize = CGSizeMake(_track.trackWidth, _track.trackHeight);
MP42SubLine *sl = [_ss getSerializedPacket]; MP42SubLine *sl = [_ss getSerializedPacket];
MP42SampleBuffer *sample; MP42SampleBuffer *sample;
@@ -130,7 +133,7 @@
sample = copyEmptySubtitleSample(_trackID, sl->end_time - sl->begin_time, NO); sample = copyEmptySubtitleSample(_trackID, sl->end_time - sl->begin_time, NO);
} }
else { else {
sample = copySubtitleSample(_trackID, sl->line, sl->end_time - sl->begin_time, sl->forced, NO, YES, CGSizeMake(0, 0), 0); sample = copySubtitleSample(_trackID, sl->line, sl->end_time - sl->begin_time, sl->forced, NO, YES, trackSize, 0);
} }
return sample; return sample;