Skip to content

Commit

Permalink
MKV-embedded SSA subtitle support enhanced.
Browse files Browse the repository at this point in the history
- text-color, italic & bold style supported.

"Disable Perian Subtitle for using QuickTime" option is
renamed to "Use Perian External Subtitles for using QuickTime".

"Use Embedded Subtitles for using QuickTime" option added.
- display or not subtitles supported as QuickTime video track.

play-panel in full-screen will show only for current movie screen.

".sami" file extension supported.

legacy preferences conversion added.

In full-navigation, nav-list fading for scrolling bug(?) fixed
- I don't know why it's occurred. OS update makes it???



git-svn-id: http://movist.googlecode.com/svn/trunk@221 9988c26d-9134-0410-b5bb-5778289bb252
  • Loading branch information
cocoable committed Jan 18, 2009
1 parent 1c260a4 commit 353c46b
Show file tree
Hide file tree
Showing 21 changed files with 554 additions and 94 deletions.
110 changes: 110 additions & 0 deletions AppController.m
Expand Up @@ -151,6 +151,113 @@ - (void)dealloc
////////////////////////////////////////////////////////////////////////////////
#pragma mark -

- (void)checkLegacyPreferences
{
// @"AutoFullScreen" is replaced with MOpeningViewKey.
id value = [_defaults objectForKey:@"AutoFullScreen"];
if (value) {
[_defaults removeObjectForKey:@"AutoFullScreen"];
if ([value boolValue] != FALSE) { // default was FALSE
[_defaults setInteger:OPENING_VIEW_FULL_SCREEN forKey:MOpeningViewKey];
}
}

// @"BlackoutSecondaryScreen" is renamed to MFullScreenBlackScreensKey.
value = [_defaults objectForKey:@"BlackoutSecondaryScreen"];
if (value) {
[_defaults removeObjectForKey:@"BlackoutSecondaryScreen"];
if ([value boolValue] != FALSE) { // default was FALSE
[_defaults setBool:TRUE forKey:MFullScreenBlackScreensKey];
}
}

// @"SubtitlePosition" is changed to MLetterBoxHeightKey and MSubtitleVPositionKey[0].
value = [_defaults objectForKey:@"SubtitlePosition"];
if (value) {
[_defaults removeObjectForKey:@"SubtitlePosition"];
if ([value intValue] != 100) { // default was 100 ("auto")
switch ([value intValue]) {
case -1 : // -1 is "on movie"
[_defaults setInteger:OSD_VPOSITION_BOTTOM forKey:MSubtitleVPositionKey[0]];
[_defaults setInteger:LETTER_BOX_HEIGHT_SAME forKey:MLetterBoxHeightKey];
break;
case 0 : // 0 is "on letter-box"
[_defaults setInteger:OSD_VPOSITION_LBOX forKey:MSubtitleVPositionKey[0]];
[_defaults setInteger:LETTER_BOX_HEIGHT_SAME forKey:MLetterBoxHeightKey];
break;
case 1 : // 1 is "on letter-box (1 line)"
[_defaults setInteger:OSD_VPOSITION_LBOX forKey:MSubtitleVPositionKey[0]];
[_defaults setInteger:LETTER_BOX_HEIGHT_1_LINE forKey:MLetterBoxHeightKey];
break;
case 2 : // 2 is "on letter-box (2 lines)"
[_defaults setInteger:OSD_VPOSITION_LBOX forKey:MSubtitleVPositionKey[0]];
[_defaults setInteger:LETTER_BOX_HEIGHT_2_LINES forKey:MLetterBoxHeightKey];
break;
case 3 : // 3 is "on letter-box (3 lines)"
[_defaults setInteger:OSD_VPOSITION_LBOX forKey:MSubtitleVPositionKey[0]];
[_defaults setInteger:LETTER_BOX_HEIGHT_3_LINES forKey:MLetterBoxHeightKey];
break;
}
}
}

// @"OpeningResize" is changed to MOpeningViewKey and MMovieResizeCenterKey.
value = [_defaults objectForKey:@"OpeningResize"];
if (value) {
[_defaults removeObjectForKey:@"OpeningResize"];
switch ([value intValue]) {
case 0 : // 0 is "never resize"
[_defaults setInteger:OPENING_VIEW_NONE forKey:MOpeningViewKey];
break;
case 1 : // 1 is "title center"
[_defaults setInteger:MOVIE_RESIZE_CENTER_TM forKey:MMovieResizeCenterKey];
break;
case 2 : // 2 is "bottom center"
[_defaults setInteger:MOVIE_RESIZE_CENTER_BM forKey:MMovieResizeCenterKey];
break;
case 3 : // 3 is "bottom right"
[_defaults setInteger:MOVIE_RESIZE_CENTER_BR forKey:MMovieResizeCenterKey];
break;
}
}

// @"WindowResize" is renamed to MWindowResizeModeKey.
value = [_defaults objectForKey:@"WindowResize"];
if (value) {
[_defaults removeObjectForKey:@"WindowResize"];
if ([value intValue] != 1) { // default was "adjust to size"
[_defaults setInteger:[value intValue] forKey:MWindowResizeModeKey];
}
}

// @"DraggingAction" is renamed to MViewDragActionKey.
value = [_defaults objectForKey:@"DraggingAction"];
if (value) {
[_defaults removeObjectForKey:@"DraggingAction"];
if ([value intValue] != 0) { // default was 0 ("none")
[_defaults setInteger:[value intValue] forKey:MViewDragActionKey];
}
}

// @"DisablePerianSubtitle" is renamed to MUsePerianExternalSubtitlesKey.
value = [_defaults objectForKey:@"DisablePerianSubtitle"];
if (value) {
[_defaults removeObjectForKey:@"DisablePerianSubtitle"];
if ([value boolValue] != TRUE) { // default was TRUE.
[_defaults setInteger:![value boolValue] forKey:MUsePerianExternalSubtitlesKey];
}
}

// @"AutoSubtitlePositionMaxLines" is renamed to MAutoLetterBoxHeightMaxLinesKey.
value = [_defaults objectForKey:@"AutoSubtitlePositionMaxLines"];
if (value) {
[_defaults removeObjectForKey:@"AutoSubtitlePositionMaxLines"];
if ([value intValue] != 2) { // default was 2.
[_defaults setInteger:[value intValue] forKey:MAutoLetterBoxHeightMaxLinesKey];
}
}
}

- (void)applicationWillFinishLaunching:(NSNotification*)aNotification
{
//TRACE(@"%s", __PRETTY_FUNCTION__);
Expand All @@ -162,6 +269,8 @@ - (void)applicationWillFinishLaunching:(NSNotification*)aNotification
[_nextMovieButton setHoverImage:[NSImage imageNamed:@"MainNextMovieHover"]];
[_playlistButton setHoverImage:[NSImage imageNamed:@"MainPlaylistHover"]];

[self checkLegacyPreferences];

// initial update preferences: general
[_mainWindow setAlwaysOnTop:[_defaults boolForKey:MAlwaysOnTopKey]];
// don't set as-desktop-background. it will be set when movie is opened.
Expand Down Expand Up @@ -231,6 +340,7 @@ - (void)applicationWillFinishLaunching:(NSNotification*)aNotification
[_movieView setRemoveGreenBox:[_defaults boolForKey:MRemoveGreenBoxKey]];

// initial update preferences: advanced - details : subtitle
[MMovie_QuickTime setUseQuickTimeEmbeddedSubtitles:[_defaults boolForKey:MUseQuickTimeEmbeddedSubtitlesKey]];
[_movieView setAutoLetterBoxHeightMaxLines:[_defaults integerForKey:MAutoLetterBoxHeightMaxLinesKey]];

// initial update preferences: advanced - details : full-nav
Expand Down
7 changes: 4 additions & 3 deletions AppController_Open.m
Expand Up @@ -109,7 +109,8 @@ - (NSArray*)subtitleFromURL:(NSURL*)subtitleURL
// find parser for subtitle's path extension
NSString* path = [subtitleURL path];
NSString* ext = [[path pathExtension] lowercaseString];
Class parserClass = ([ext isEqualToString:@"smi"]) ? [MSubtitleParser_SMI class] :
Class parserClass = ([ext isEqualToString:@"smi"] ||
[ext isEqualToString:@"sami"])? [MSubtitleParser_SMI class] :
([ext isEqualToString:@"srt"]) ? [MSubtitleParser_SRT class] :
([ext isEqualToString:@"mkv"] ||
[ext isEqualToString:@"mks"]) ? [MSubtitleParser_MKV class] :
Expand Down Expand Up @@ -217,10 +218,10 @@ - (void)updateUIForOpenedMovieAndSubtitle
[_movieView setMessageWithURL:[self movieURL] info:[[_movie class] name]];
}

if (![self isFullScreen] && ![self isDesktopBackground]) {
if (_mainWindow == [_movieView window]) {
switch ([_defaults integerForKey:MOpeningViewKey]) {
case OPENING_VIEW_HALF_SIZE : [self resizeWithMagnification:0.5]; break;
case OPENING_VIEW_REAL_SIZE : [self resizeWithMagnification:1.0]; break;
case OPENING_VIEW_NORMAL_SIZE : [self resizeWithMagnification:1.0]; break;
case OPENING_VIEW_DOUBLE_SIZE : [self resizeWithMagnification:2.0]; break;
case OPENING_VIEW_FIT_TO_SCREEN : [self resizeToScreen]; break;
case OPENING_VIEW_DESKTOP_BACKGROUND: [self beginDesktopBackground]; break;
Expand Down
3 changes: 2 additions & 1 deletion English.lproj/Localizable.strings
Expand Up @@ -154,7 +154,8 @@
"Remove Green Box" = "Remove Green Box";

/* Preferences: advanced - details: subtitle */
"Disable Perian Subtitle for using QuickTime" = "Disable Perian Subtitle for using QuickTime";
"Use Perian External Subtitles for using QuickTime" = "Use Perian External Subtitles for using QuickTime";
"Use Embedded Subtitles for using QuickTime" = "Use Embedded Subtitles for using QuickTime";
"Auto-Load Embedded Subtitles in MKV" = "Auto-Load Embedded Subtitles in MKV";
"Replace New-Line with <BR> for SAMI" = "Replace New-Line with <BR> for SAMI";
"Default Subtitle Language Identifiers" = "Default Subtitle Language Identifiers";
Expand Down
20 changes: 8 additions & 12 deletions FullNavListView.m
Expand Up @@ -190,36 +190,32 @@ - (id)initWithFrame:(NSRect)frame window:(NSWindow*)window

CIColor* c0 = [CIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0];
CIColor* c1 = [CIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
CIVector* p0 = [CIVector vectorWithX:0 Y:_itemHeight];
CIVector* p1 = [CIVector vectorWithX:0 Y:0];
if (isSystemTiger()) { CIVector* p; p = p0, p0 = p1, p1 = p; }
CIVector* p0 = [CIVector vectorWithX:0 Y:0];
CIVector* p1 = [CIVector vectorWithX:0 Y:_itemHeight];
_tFilter = [[CIFilter filterWithName:@"CILinearGradient"] retain];
[_tFilter setValue:p0 forKey:@"inputPoint0"];
[_tFilter setValue:p1 forKey:@"inputPoint1"];
[_tFilter setValue:c0 forKey:@"inputColor0"];
[_tFilter setValue:c1 forKey:@"inputColor1"];

p0 = [CIVector vectorWithX:0 Y:0];
p1 = [CIVector vectorWithX:0 Y:_itemHeight];
if (isSystemTiger()) { CIVector* p; p = p0, p0 = p1, p1 = p; }
p0 = [CIVector vectorWithX:0 Y:_itemHeight];
p1 = [CIVector vectorWithX:0 Y:0];
_bFilter = [[CIFilter filterWithName:@"CILinearGradient"] retain];
[_bFilter setValue:p0 forKey:@"inputPoint0"];
[_bFilter setValue:p1 forKey:@"inputPoint1"];
[_bFilter setValue:c0 forKey:@"inputColor0"];
[_bFilter setValue:c1 forKey:@"inputColor1"];

p0 = [CIVector vectorWithX:0 Y:0];
p1 = [CIVector vectorWithX:ITEM_HSCROLL_FADE_SIZE Y:0];
if (isSystemTiger()) { CIVector* p; p = p0, p0 = p1, p1 = p; }
p0 = [CIVector vectorWithX:ITEM_HSCROLL_FADE_SIZE Y:0];
p1 = [CIVector vectorWithX:0 Y:0];
_lFilter = [[CIFilter filterWithName:@"CILinearGradient"] retain];
[_lFilter setValue:p0 forKey:@"inputPoint0"];
[_lFilter setValue:p1 forKey:@"inputPoint1"];
[_lFilter setValue:c0 forKey:@"inputColor0"];
[_lFilter setValue:c1 forKey:@"inputColor1"];

p0 = [CIVector vectorWithX:ITEM_HSCROLL_FADE_SIZE Y:0];
p1 = [CIVector vectorWithX:0 Y:0];
if (isSystemTiger()) { CIVector* p; p = p0, p0 = p1, p1 = p; }
p0 = [CIVector vectorWithX:0 Y:0];
p1 = [CIVector vectorWithX:ITEM_HSCROLL_FADE_SIZE Y:0];
_rFilter = [[CIFilter filterWithName:@"CILinearGradient"] retain];
[_rFilter setValue:p0 forKey:@"inputPoint0"];
[_rFilter setValue:p1 forKey:@"inputPoint1"];
Expand Down
3 changes: 2 additions & 1 deletion FullWindow.m
Expand Up @@ -103,7 +103,8 @@ - (BOOL)canBecomeKeyWindow { return TRUE; }
- (void)mouseMoved:(NSEvent*)event
{
//TRACE(@"%s", __PRETTY_FUNCTION__);
if ([self isVisible] && ![self isNavigating]) {
if (NSPointInRect([NSEvent mouseLocation], [self frame]) &&
[self isVisible] && ![self isNavigating]) {
[_playPanel showPanel];

NSPoint p = [self convertBaseToScreen:[event locationInWindow]];
Expand Down
1 change: 1 addition & 0 deletions Info.plist
Expand Up @@ -326,6 +326,7 @@
<key>CFBundleTypeExtensions</key>
<array>
<string>smi</string>
<string>sami</string>
</array>
<key>CFBundleTypeName</key>
<string>Subtitle-SMI</string>
Expand Down
Binary file modified Korean.lproj/Localizable.strings
Binary file not shown.
2 changes: 2 additions & 0 deletions MMovie_QuickTime.h
Expand Up @@ -35,4 +35,6 @@
+ (NSString*)name;
+ (void)checkA52CodecAndPerianInstalled;

+ (void)setUseQuickTimeEmbeddedSubtitles:(BOOL)use;

@end
16 changes: 14 additions & 2 deletions MMovie_QuickTime.m
Expand Up @@ -114,7 +114,7 @@ - (void)initA52CodecAndPerian:(BOOL)digitalAudioOut
}
if (_perianInstalled) {
_perianSubtitleEnabled = [defaults isPerianSubtitleEnabled];
if ([defaults boolForKey:MDisablePerianSubtitleKey]) {
if (![defaults boolForKey:MUsePerianExternalSubtitlesKey]) {
[defaults setPerianSubtitleEnabled:FALSE];
}
}
Expand All @@ -132,6 +132,13 @@ - (void)cleanupA52CodecAndPerian
}
}

static BOOL _useQuickTimeEmbeddedSubtitles;

+ (void)setUseQuickTimeEmbeddedSubtitles:(BOOL)use
{
_useQuickTimeEmbeddedSubtitles = use;
}

- (MTrack*)videoTrackWithIndex:(int)index qtTrack:(QTTrack*)qtTrack
{
NSSize displaySize = [[qtTrack attributeForKey:QTTrackDimensionsAttribute] sizeValue];
Expand Down Expand Up @@ -239,7 +246,12 @@ - (id)initWithURL:(NSURL*)url movieInfo:(MMovieInfo*)movieInfo
if ([mediaType isEqualToString:QTMediaTypeVideo] ||
[mediaType isEqualToString:QTMediaTypeMPEG]/* ||
[mediaType isEqualToString:QTMediaTypeMovie]*/) {
[vTracks addObject:[self videoTrackWithIndex:vi++ qtTrack:qtTrack]];
if (vi < [_videoTracks count] || _useQuickTimeEmbeddedSubtitles) {
[vTracks addObject:[self videoTrackWithIndex:vi++ qtTrack:qtTrack]];
}
else {
[qtTrack setEnabled:FALSE];
}
}
else if ([mediaType isEqualToString:QTMediaTypeSound]/* ||
[mediaType isEqualToString:QTMediaTypeMusic]*/) {
Expand Down
3 changes: 3 additions & 0 deletions MSubtitle.h
Expand Up @@ -31,6 +31,7 @@
NSString* _type;
NSString* _name;
NSString* _language;
NSString* _extraInfo;
NSString* _trackName;
BOOL _embedded;
BOOL _enabled;
Expand Down Expand Up @@ -63,12 +64,14 @@
- (NSString*)type;
- (NSString*)name;
- (NSString*)language;
- (NSString*)extraInfo;
- (NSString*)trackName;
- (NSString*)summary;
- (BOOL)isEmbedded;
- (void)setType:(NSString*)type;
- (void)setName:(NSString*)name;
- (void)setLanguage:(NSString*)language;
- (void)setExtraInfo:(NSString*)extraInfo;
- (void)setTrackName:(NSString*)trackName;
- (void)setEmbedded:(BOOL)embedded;

Expand Down
6 changes: 5 additions & 1 deletion MSubtitle.m
Expand Up @@ -67,6 +67,7 @@ - (void)dealloc

[_items release];
[_trackName release];
[_extraInfo release];
[_language release];
[_name release];
[_type release];
Expand All @@ -80,11 +81,13 @@ - (NSURL*)url { return _url; }
- (NSString*)type { return _type; }
- (NSString*)name { return _name; }
- (NSString*)language { return _language; }
- (NSString*)extraInfo { return _extraInfo; }
- (NSString*)trackName { return _trackName; }
- (BOOL)isEmbedded { return _embedded; }
- (void)setType:(NSString*)s { [s retain], [_type release], _type = s; }
- (void)setName:(NSString*)s { [s retain], [_name release], _name = s; }
- (void)setLanguage:(NSString*)s { [s retain], [_language release], _language = s; }
- (void)setExtraInfo:(NSString*)s { [s retain], [_extraInfo release], _extraInfo = s; }
- (void)setTrackName:(NSString*)s { [s retain], [_trackName release], _trackName = s; }
- (void)setEmbedded:(BOOL)embedded { _embedded = embedded; }
- (NSString*)summary
Expand All @@ -98,7 +101,8 @@ - (BOOL)checkDefaultLanguage:(NSArray*)defaultLangIDs
NSEnumerator* e = [defaultLangIDs objectEnumerator];
while (s = [e nextObject]) {
if ([_name rangeOfString:s options:NSCaseInsensitiveSearch].location != NSNotFound ||
[_language rangeOfString:s options:NSCaseInsensitiveSearch].location != NSNotFound) {
[_language rangeOfString:s options:NSCaseInsensitiveSearch].location != NSNotFound ||
[_extraInfo rangeOfString:s options:NSCaseInsensitiveSearch].location != NSNotFound) {
return TRUE;
}
}
Expand Down
4 changes: 4 additions & 0 deletions MSubtitleParser.h
Expand Up @@ -37,6 +37,10 @@
- (NSArray*)parseString:(NSString*)string options:(NSDictionary*)options
error:(NSError**)error;

- (void)mutableAttributedString:(NSMutableAttributedString*)mas
appendString:(NSString*)string
withColor:(NSColor*)color italic:(BOOL)italic bold:(BOOL)bold;

@end

extern NSString* MSubtitleParserOptionKey_stringEncoding;
26 changes: 26 additions & 0 deletions MSubtitleParser.m
Expand Up @@ -109,4 +109,30 @@ - (NSArray*)parseString:(NSString*)string options:(NSDictionary*)options
return nil;
}

- (void)mutableAttributedString:(NSMutableAttributedString*)mas
appendString:(NSString*)string
withColor:(NSColor*)color italic:(BOOL)italic bold:(BOOL)bold
{
//TRACE(@"%s \"%@\" + \"%@\" with %@, %@, %@", __PRETTY_FUNCTION__,
// [mas string], string, color, italic ? @"italic" : @"-", bold ? @"bold" : @"-");
if (color || italic || bold) {
NSMutableDictionary* attrs = [NSMutableDictionary dictionaryWithCapacity:3];
if (color) {
[attrs setObject:color forKey:NSForegroundColorAttributeName];
}
if (italic) {
[attrs setObject:[NSNumber numberWithBool:TRUE] forKey:MFontItalicAttributeName];
}
if (bold) {
[attrs setObject:[NSNumber numberWithBool:TRUE] forKey:MFontBoldAttributeName];
}
[mas appendAttributedString:[[[NSAttributedString alloc]
initWithString:string attributes:attrs] autorelease]];
}
else {
[mas appendAttributedString:[[[NSAttributedString alloc]
initWithString:string] autorelease]];
}
}

@end

0 comments on commit 353c46b

Please sign in to comment.