Changeset 1122
- Timestamp:
- 08/12/09 17:55:53 (7 months ago)
- Files:
-
- trunk/Perian.xcodeproj/project.pbxproj (modified) (19 diffs)
- trunk/Subtitles/SubATSUIRenderer.h (modified) (1 diff)
- trunk/Subtitles/SubATSUIRenderer.m (modified) (2 diffs)
- trunk/Subtitles/ssa2pdf.m (copied) (copied from trunk/Subtitles/ssa2html.m) (2 diffs)
- trunk/TextSubCodec.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Perian.xcodeproj/project.pbxproj
r1119 r1122 120 120 3D41BEB40BCD3B510069E7C2 /* libuniversaldetector.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3D41BE9A0BCD3B330069E7C2 /* libuniversaldetector.a */; }; 121 121 3D4A7A990B5533BC004C5D6A /* ColorConversions.c in Sources */ = {isa = PBXBuildFile; fileRef = 3D4A7A980B5533BC004C5D6A /* ColorConversions.c */; settings = {COMPILER_FLAGS = "-O3 -fweb -fno-reorder-blocks -fomit-frame-pointer"; }; }; 122 3D802EAB1032B8B00034BF4A /* SubContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 3D211A1F0B6B1A540051299D /* SubContext.m */; }; 123 3D802EAC1032B8B00034BF4A /* SubImport.mm in Sources */ = {isa = PBXBuildFile; fileRef = 61D514DD0ADF3DBA00A671E1 /* SubImport.mm */; }; 124 3D802EAD1032B8B00034BF4A /* SubParsing.m.rl in Sources */ = {isa = PBXBuildFile; fileRef = 3D211A2F0B6B1AD80051299D /* SubParsing.m.rl */; }; 125 3D802EAE1032B8B00034BF4A /* SubUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 3D211A220B6B1A660051299D /* SubUtilities.m */; }; 126 3D802EAF1032B8B00034BF4A /* Codecprintf.c in Sources */ = {isa = PBXBuildFile; fileRef = 113F58990A6B091600509987 /* Codecprintf.c */; }; 127 3D802EB11032B8B00034BF4A /* libobjc.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 3DAD08570FBF80D8001E156F /* libobjc.dylib */; }; 128 3D802EB21032B8B00034BF4A /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F57755F40B51EB1800C7D833 /* CoreFoundation.framework */; }; 129 3D802EB31032B8B00034BF4A /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F539CD110B62BC82005A72C9 /* Foundation.framework */; }; 130 3D802EB41032B8B00034BF4A /* libuniversaldetector.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3D41BE9A0BCD3B330069E7C2 /* libuniversaldetector.a */; }; 131 3D802EB51032B8B00034BF4A /* libstdc++.6.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 3DAD0A110FBFB145001E156F /* libstdc++.6.dylib */; }; 132 3D802EBF1032B9860034BF4A /* SubATSUIRenderer.m in Sources */ = {isa = PBXBuildFile; fileRef = 3DB2BB280B6C92F000416863 /* SubATSUIRenderer.m */; }; 133 3D802EC31032B9B50034BF4A /* ssa2pdf.m in Sources */ = {isa = PBXBuildFile; fileRef = 3D802EC21032B9B50034BF4A /* ssa2pdf.m */; }; 134 3D802F06103365DB0034BF4A /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 11629EEA0B51E4F1006591C8 /* Cocoa.framework */; }; 135 3D802F171033662F0034BF4A /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 11D4EEFC0A3CE7FA0066D45F /* Carbon.framework */; }; 136 3D802F8610336EE90034BF4A /* ApplicationServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3D802F8510336EE90034BF4A /* ApplicationServices.framework */; }; 122 137 3D95B9010E208965007C8F51 /* libbz2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 3D95B9000E208965007C8F51 /* libbz2.dylib */; }; 123 138 3D95B9020E20896F007C8F51 /* libbz2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 3D95B9000E208965007C8F51 /* libbz2.dylib */; }; … … 295 310 script = "RAGEL=${PROJECT_DIR}/Binaries/ragel\nRLCODEGEN=${PROJECT_DIR}/Binaries/rlgen-cd\n[ ${INPUT_FILE_PATH} -nt ${DERIVED_FILES_DIR}/${INPUT_FILE_BASE} ] || exit 0\n${RAGEL} ${INPUT_FILE_PATH} | ${RLCODEGEN} -T0 -o ${DERIVED_FILES_DIR}/${INPUT_FILE_BASE}\n"; 296 311 }; 312 3D802EB61032B8B00034BF4A /* PBXBuildRule */ = { 313 isa = PBXBuildRule; 314 compilerSpec = com.apple.compilers.proxy.script; 315 filePatterns = "*.rl"; 316 fileType = pattern.proxy; 317 isEditable = 1; 318 outputFiles = ( 319 "$(DERIVED_FILES_DIR)/$(INPUT_FILE_BASE)", 320 ); 321 script = "RAGEL=${PROJECT_DIR}/Binaries/ragel\nRLCODEGEN=${PROJECT_DIR}/Binaries/rlgen-cd\n[ ${INPUT_FILE_PATH} -nt ${DERIVED_FILES_DIR}/${INPUT_FILE_BASE} ] || exit 0\n${RAGEL} ${INPUT_FILE_PATH} | ${RLCODEGEN} -T0 -o ${DERIVED_FILES_DIR}/${INPUT_FILE_BASE}\n"; 322 }; 297 323 3DAD086E0FBF8225001E156F /* PBXBuildRule */ = { 298 324 isa = PBXBuildRule; … … 346 372 proxyType = 2; 347 373 remoteGlobalIDString = 3DBF4F570BCD396800DA401A; 374 remoteInfo = universaldetector; 375 }; 376 3D802EA81032B8B00034BF4A /* PBXContainerItemProxy */ = { 377 isa = PBXContainerItemProxy; 378 containerPortal = 3D41BE8C0BCD3B330069E7C2 /* UniversalDetector.xcodeproj */; 379 proxyType = 1; 380 remoteGlobalIDString = 3DBF4F560BCD396800DA401A; 348 381 remoteInfo = universaldetector; 349 382 }; … … 566 599 3D4A7A970B5533BC004C5D6A /* ColorConversions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ColorConversions.h; sourceTree = "<group>"; }; 567 600 3D4A7A980B5533BC004C5D6A /* ColorConversions.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ColorConversions.c; sourceTree = "<group>"; }; 601 3D802EBB1032B8B00034BF4A /* ssa2pdf */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = ssa2pdf; sourceTree = BUILT_PRODUCTS_DIR; }; 602 3D802EC21032B9B50034BF4A /* ssa2pdf.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ssa2pdf.m; path = Subtitles/ssa2pdf.m; sourceTree = "<group>"; }; 603 3D802F8510336EE90034BF4A /* ApplicationServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ApplicationServices.framework; path = /System/Library/Frameworks/ApplicationServices.framework; sourceTree = "<absolute>"; }; 568 604 3D95B9000E208965007C8F51 /* libbz2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libbz2.dylib; path = /usr/lib/libbz2.dylib; sourceTree = "<absolute>"; }; 569 605 3DAD08080FBF7C6F001E156F /* ssa2html */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = ssa2html; sourceTree = BUILT_PRODUCTS_DIR; }; … … 790 826 runOnlyForDeploymentPostprocessing = 0; 791 827 }; 828 3D802EB01032B8B00034BF4A /* Frameworks */ = { 829 isa = PBXFrameworksBuildPhase; 830 buildActionMask = 2147483647; 831 files = ( 832 3D802EB11032B8B00034BF4A /* libobjc.dylib in Frameworks */, 833 3D802EB21032B8B00034BF4A /* CoreFoundation.framework in Frameworks */, 834 3D802EB31032B8B00034BF4A /* Foundation.framework in Frameworks */, 835 3D802EB41032B8B00034BF4A /* libuniversaldetector.a in Frameworks */, 836 3D802EB51032B8B00034BF4A /* libstdc++.6.dylib in Frameworks */, 837 3D802F06103365DB0034BF4A /* Cocoa.framework in Frameworks */, 838 3D802F171033662F0034BF4A /* Carbon.framework in Frameworks */, 839 3D802F8610336EE90034BF4A /* ApplicationServices.framework in Frameworks */, 840 ); 841 runOnlyForDeploymentPostprocessing = 0; 842 }; 792 843 3DAD08060FBF7C6F001E156F /* Frameworks */ = { 793 844 isa = PBXFrameworksBuildPhase; … … 870 921 isa = PBXGroup; 871 922 children = ( 923 3D802F8510336EE90034BF4A /* ApplicationServices.framework */, 872 924 3DAD0A110FBFB145001E156F /* libstdc++.6.dylib */, 873 925 3DAD08570FBF80D8001E156F /* libobjc.dylib */, … … 985 1037 3DAD08080FBF7C6F001E156F /* ssa2html */, 986 1038 3DAD09A80FBFAB08001E156F /* detect-encoding */, 1039 3D802EBB1032B8B00034BF4A /* ssa2pdf */, 987 1040 ); 988 1041 name = Products; … … 1051 1104 3DAD09AE0FBFAB68001E156F /* detect-encoding.m */, 1052 1105 3DAD08240FBF7DA9001E156F /* ssa2html.m */, 1106 3D802EC21032B9B50034BF4A /* ssa2pdf.m */, 1053 1107 3DB2BB270B6C92F000416863 /* SubATSUIRenderer.h */, 1054 1108 3DB2BB280B6C92F000416863 /* SubATSUIRenderer.m */, … … 1413 1467 productType = "com.apple.product-type.bundle"; 1414 1468 }; 1469 3D802EA61032B8B00034BF4A /* ssa2pdf */ = { 1470 isa = PBXNativeTarget; 1471 buildConfigurationList = 3D802EB71032B8B00034BF4A /* Build configuration list for PBXNativeTarget "ssa2pdf" */; 1472 buildPhases = ( 1473 3D802EA91032B8B00034BF4A /* Sources */, 1474 3D802EB01032B8B00034BF4A /* Frameworks */, 1475 ); 1476 buildRules = ( 1477 3D802EB61032B8B00034BF4A /* PBXBuildRule */, 1478 ); 1479 dependencies = ( 1480 3D802EA71032B8B00034BF4A /* PBXTargetDependency */, 1481 ); 1482 name = ssa2pdf; 1483 productName = ssa2html; 1484 productReference = 3D802EBB1032B8B00034BF4A /* ssa2pdf */; 1485 productType = "com.apple.product-type.tool"; 1486 }; 1415 1487 3DAD08070FBF7C6F001E156F /* ssa2html */ = { 1416 1488 isa = PBXNativeTarget; … … 1563 1635 3DAD08070FBF7C6F001E156F /* ssa2html */, 1564 1636 3DAD09A70FBFAB08001E156F /* detect-encoding */, 1637 3D802EA61032B8B00034BF4A /* ssa2pdf */, 1565 1638 ); 1566 1639 }; … … 1803 1876 runOnlyForDeploymentPostprocessing = 0; 1804 1877 }; 1878 3D802EA91032B8B00034BF4A /* Sources */ = { 1879 isa = PBXSourcesBuildPhase; 1880 buildActionMask = 2147483647; 1881 files = ( 1882 3D802EAB1032B8B00034BF4A /* SubContext.m in Sources */, 1883 3D802EAC1032B8B00034BF4A /* SubImport.mm in Sources */, 1884 3D802EAD1032B8B00034BF4A /* SubParsing.m.rl in Sources */, 1885 3D802EAE1032B8B00034BF4A /* SubUtilities.m in Sources */, 1886 3D802EAF1032B8B00034BF4A /* Codecprintf.c in Sources */, 1887 3D802EBF1032B9860034BF4A /* SubATSUIRenderer.m in Sources */, 1888 3D802EC31032B9B50034BF4A /* ssa2pdf.m in Sources */, 1889 ); 1890 runOnlyForDeploymentPostprocessing = 0; 1891 }; 1805 1892 3DAD08050FBF7C6F001E156F /* Sources */ = { 1806 1893 isa = PBXSourcesBuildPhase; … … 1908 1995 target = 11BA39A80A61E450008AF206 /* ffmpeg Static Libraries */; 1909 1996 targetProxy = 11BA3DAF0A61EE90008AF206 /* PBXContainerItemProxy */; 1997 }; 1998 3D802EA71032B8B00034BF4A /* PBXTargetDependency */ = { 1999 isa = PBXTargetDependency; 2000 name = universaldetector; 2001 targetProxy = 3D802EA81032B8B00034BF4A /* PBXContainerItemProxy */; 1910 2002 }; 1911 2003 3DAD08920FBF84A4001E156F /* PBXTargetDependency */ = { … … 2136 2228 DEAD_CODE_STRIPPING = YES; 2137 2229 DEBUG_INFORMATION_FORMAT = dwarf; 2230 DEPLOYMENT_POSTPROCESSING = YES; 2138 2231 GCC_ALTIVEC_EXTENSIONS = YES; 2139 2232 GCC_DYNAMIC_NO_PIC = YES; … … 2155 2248 SCAN_ALL_SOURCE_FILES_FOR_INCLUDES = YES; 2156 2249 SDKROOT = macosx10.4; 2250 STRIP_STYLE = debugging; 2157 2251 }; 2158 2252 name = Deployment; … … 2300 2394 INFOPLIST_PREPROCESS = YES; 2301 2395 INSTALL_PATH = "$(HOME)/Library/Bundles"; 2396 "MACOSX_DEPLOYMENT_TARGET[arch=x86_64]" = 10.5; 2302 2397 PRODUCT_NAME = Perian; 2303 2398 SDKROOT = macosx10.4; … … 2349 2444 name = "Deployment+Debug"; 2350 2445 }; 2446 3D802EB81032B8B00034BF4A /* Development */ = { 2447 isa = XCBuildConfiguration; 2448 buildSettings = { 2449 ALWAYS_SEARCH_USER_PATHS = NO; 2450 COPY_PHASE_STRIP = NO; 2451 FRAMEWORK_SEARCH_PATHS = ( 2452 "$(inherited)", 2453 "\"$(DEVELOPER_DIR)/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks\"", 2454 "\"$(SYSTEM_LIBRARY_DIR)/Frameworks/ApplicationServices.framework/Versions/A/Frameworks\"", 2455 ); 2456 GCC_MODEL_TUNING = G5; 2457 GCC_OPTIMIZATION_LEVEL = 0; 2458 INSTALL_PATH = /usr/local/bin; 2459 PREBINDING = NO; 2460 PRODUCT_NAME = ssa2pdf; 2461 }; 2462 name = Development; 2463 }; 2464 3D802EB91032B8B00034BF4A /* Deployment */ = { 2465 isa = XCBuildConfiguration; 2466 buildSettings = { 2467 ALWAYS_SEARCH_USER_PATHS = NO; 2468 COPY_PHASE_STRIP = YES; 2469 FRAMEWORK_SEARCH_PATHS = ( 2470 "$(inherited)", 2471 "\"$(DEVELOPER_DIR)/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks\"", 2472 "\"$(SYSTEM_LIBRARY_DIR)/Frameworks/ApplicationServices.framework/Versions/A/Frameworks\"", 2473 ); 2474 GCC_MODEL_TUNING = G5; 2475 INSTALL_PATH = /usr/local/bin; 2476 PREBINDING = NO; 2477 PRODUCT_NAME = ssa2pdf; 2478 }; 2479 name = Deployment; 2480 }; 2481 3D802EBA1032B8B00034BF4A /* Deployment+Debug */ = { 2482 isa = XCBuildConfiguration; 2483 buildSettings = { 2484 ALWAYS_SEARCH_USER_PATHS = NO; 2485 FRAMEWORK_SEARCH_PATHS = ( 2486 "$(inherited)", 2487 "\"$(DEVELOPER_DIR)/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks\"", 2488 "\"$(SYSTEM_LIBRARY_DIR)/Frameworks/ApplicationServices.framework/Versions/A/Frameworks\"", 2489 ); 2490 GCC_MODEL_TUNING = G5; 2491 INSTALL_PATH = /usr/local/bin; 2492 PRODUCT_NAME = ssa2pdf; 2493 }; 2494 name = "Deployment+Debug"; 2495 }; 2351 2496 3DAD080A0FBF7C70001E156F /* Development */ = { 2352 2497 isa = XCBuildConfiguration; … … 2500 2645 INFOPLIST_PREPROCESS = YES; 2501 2646 INSTALL_PATH = "$(HOME)/Library/Bundles"; 2647 "MACOSX_DEPLOYMENT_TARGET[arch=x86_64]" = 10.5; 2502 2648 PRODUCT_NAME = Perian; 2503 2649 SDKROOT = macosx10.4; … … 2531 2677 INFOPLIST_PREPROCESS = YES; 2532 2678 INSTALL_PATH = "$(HOME)/Library/Bundles"; 2679 "MACOSX_DEPLOYMENT_TARGET[arch=x86_64]" = 10.5; 2533 2680 PRODUCT_NAME = Perian; 2534 2681 SDKROOT = macosx10.4; … … 2726 2873 defaultConfigurationName = "Deployment+Debug"; 2727 2874 }; 2875 3D802EB71032B8B00034BF4A /* Build configuration list for PBXNativeTarget "ssa2pdf" */ = { 2876 isa = XCConfigurationList; 2877 buildConfigurations = ( 2878 3D802EB81032B8B00034BF4A /* Development */, 2879 3D802EB91032B8B00034BF4A /* Deployment */, 2880 3D802EBA1032B8B00034BF4A /* Deployment+Debug */, 2881 ); 2882 defaultConfigurationIsVisible = 0; 2883 defaultConfigurationName = "Deployment+Debug"; 2884 }; 2728 2885 3DAD080D0FBF7C71001E156F /* Build configuration list for PBXNativeTarget "ssa2html" */ = { 2729 2886 isa = XCConfigurationList; trunk/Subtitles/SubATSUIRenderer.h
r1098 r1122 53 53 #endif 54 54 55 extern SubtitleRendererPtr SubInit ForSSA(char *header, size_t headerLen, int width, int height);55 extern SubtitleRendererPtr SubInitSSA(char *header, size_t headerLen, int width, int height); 56 56 extern SubtitleRendererPtr SubInitNonSSA(int width, int height); 57 57 extern CGColorSpaceRef SubGetColorSpace(SubtitleRendererPtr s); trunk/Subtitles/SubATSUIRenderer.m
r1103 r1122 1208 1208 } 1209 1209 1210 SubtitleRendererPtr SubInit ForSSA(char *header, size_t headerLen, int width, int height)1210 SubtitleRendererPtr SubInitSSA(char *header, size_t headerLen, int width, int height) 1211 1211 { 1212 1212 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; … … 1241 1241 void SubPrerollFromHeader(char *header, int headerLen) 1242 1242 { 1243 SubtitleRendererPtr s = headerLen ? SubInit ForSSA(header, headerLen, 640, 480)1243 SubtitleRendererPtr s = headerLen ? SubInitSSA(header, headerLen, 640, 480) 1244 1244 : SubInitNonSSA(640, 480); 1245 1245 /* trunk/Subtitles/ssa2pdf.m
r1063 r1122 1 1 /* 2 * ssa2html 3 * Created by Alexander Strange on 7/28/07. 4 * 5 * A primitive .ssa/.ass to HTML converter. 2 * ssa2pdf 3 * Created by Alexander Strange on 8/11/09. 6 4 * 7 5 * This file is part of Perian. … … 22 20 */ 23 21 22 #import <ApplicationServices/ApplicationServices.h> 24 23 #import "SubImport.h" 25 24 #import "SubParsing.h" 26 25 27 @interface SubHTMLExporter : SubRenderer 28 { 29 SubContext *sc; 30 @public; 31 NSMutableString *html; 32 } 33 34 @end 35 36 @implementation SubHTMLExporter 37 -(SubHTMLExporter*)init 38 { 39 if (self = [super init]) 40 { 41 html = [[NSMutableString alloc] init]; 42 [html appendString:@"<html>\n"]; 43 [html appendString:@"<head>\n"]; 44 [html appendString:@"<meta http-equiv=\"Content-type\" content=\"text/html; charset=UTF-8\" />\n"]; 45 [html appendString:@"<meta name=\"generator\" content=\"ssa2html\" />\n"]; 46 } 47 48 return self; 49 } 50 51 -(void)dealloc 52 { 53 [sc release]; 54 [html release]; 55 [super dealloc]; 56 } 57 58 -(void)completedHeaderParsing:(SubContext*)sc_ 59 { 60 sc = sc_; 61 [html appendFormat:@"<title>%@</title>\n",[sc->headers objectForKey:@"Title"]]; 62 [html appendString:@"<style type=\"text/css\">\n"]; 63 [html appendFormat:@".screen {width: %fpx; height: %fpx; background-color: gray; position: relative; display: table}\n.bottom {bottom: 20px; position: absolute} .top {top: 20px; position: absolute}\n",sc->resX,sc->resY]; 64 } 65 66 static const NSString *haligns[] = {@"left", @"center", @"right"}; 67 static const NSString *valigns[] = {@"bottom", @"middle", @"top"}; 68 69 // font-weight actually seems to be enumerated 100|200|...|900 70 // but, like, whatever 71 static NSString *FontWeightStringForWeight(Float32 weight) 72 { 73 if (weight == 0) 74 return @"normal"; 75 else if (weight == 1) 76 return @"bold"; 77 else 78 return [NSString stringWithFormat:@"%d", (int)weight]; 79 } 80 81 -(void*)completedStyleParsing:(SubStyle*)s 82 { 83 [html appendFormat:@".%@ {display: table-cell; clear: none;\n",s->name]; 84 [html appendFormat:@"font-family: \"%@\"; ",s->fontname]; 85 [html appendFormat:@"font-size: %fpt;\n",s->size * (72./96.)]; 86 [html appendFormat:@"color: #%X%X%X;\n",(int)(s->primaryColor.red*255.),(int)(s->primaryColor.green*255.),(int)(s->primaryColor.blue*255.)]; 87 [html appendFormat:@"-webkit-text-stroke-color: #%X%X%X;\n",(int)(s->outlineColor.red*255.),(int)(s->outlineColor.green*255.),(int)(s->outlineColor.blue*255.)]; 88 [html appendFormat:@"letter-spacing: %fpx;\n",s->tracking]; 89 // [html appendFormat:@"-webkit-text-stroke-width: %fpx;\n",s->outlineRadius]; 90 [html appendFormat:@"text-shadow: #%X%X%X %fpx %fpx 0;\n",(int)(s->shadowColor.red*255.),(int)(s->shadowColor.green*255.),(int)(s->shadowColor.blue*255.), 91 s->shadowDist*2., s->shadowDist*2.]; 92 [html appendFormat:@"text-outline: #%X%X%X %fpx 0;\n",(int)(s->shadowColor.red*255.),(int)(s->shadowColor.green*255.),(int)(s->shadowColor.blue*255.), 93 s->outlineRadius]; 94 [html appendFormat:@"width: %fpx;\n",sc->resX - s->marginL - s->marginR]; 95 [html appendFormat:@"font-weight: %@; font-style: %@; text-decoration: %@;\n",FontWeightStringForWeight(s->weight), s->italic ? @"italic" : @"normal", s->underline ? @"underline" : (s->strikeout ? @"line-through" : @"none")]; 96 [html appendFormat:@"text-align: %@;\n", haligns[s->alignH]]; 97 [html appendFormat:@"vertical-align: %@;\n", valigns[s->alignV]]; 98 [html appendString:@"}\n"]; 99 100 return nil; 101 } 102 103 -(void)endOfHead 104 { 105 [html appendString:@"</style>\n"]; 106 [html appendString:@"</head>\n"]; 107 [html appendString:@"<body>\n"]; 108 } 109 110 NSString *htmlfilter(NSString *s) 111 { 112 NSMutableString *ms = [[s mutableCopy] autorelease]; 113 114 [ms replaceOccurrencesOfString:@"\n" withString:@"<br>\n" options:0 range:NSMakeRange(0, [ms length])]; 115 // [ms replaceOccurrencesOfString:[NSString stringWithFormat:@"%C",0x00A0] withString:@" " options:0 range:NSMakeRange(0, [ms length])]; 116 return ms; 117 } 118 119 -(void*)spanExtraFromRenderDiv:(SubRenderDiv*)div 120 { 121 return [[NSMutableString string] retain]; 122 } 123 124 -(void*)cloneSpanExtra:(SubRenderSpan*)span 125 { 126 return [[NSMutableString string] retain]; 127 } 128 129 -(void)releaseSpanExtra:(void*)ex 130 { 131 NSMutableString *s = (NSMutableString*)ex; 132 [s release]; 133 } 134 135 -(void)spanChangedTag:(SSATagType)tag span:(SubRenderSpan*)span div:(SubRenderDiv*)div param:(void*)p 136 { 137 NSMutableString *sty = span->ex; 138 int ip; 139 NSString *sp; 140 float fp; 141 142 143 #define iv() ip = *(int*)p; 144 #define sv() sp = *(NSString**)p; 145 #define fv() fp = *(float*)p; 146 #define cv() ip = *(int*)p; ip = EndianU32_BtoL(ip); ip = ip & 0xFFFFFF; 147 148 switch (tag) { 149 case tag_b: 150 iv(); 151 [sty appendFormat:@"font-weight: %@; ", ip? @"bold" : @"normal"]; 152 break; 153 case tag_i: 154 iv(); 155 [sty appendFormat:@"font-style: %@; ", ip? @"italic" : @"normal"]; 156 break; 157 case tag_u: 158 iv(); 159 [sty appendFormat:@"text-decoration: %@; ", ip? @"underline" : @"none"]; 160 break; 161 case tag_s: 162 iv(); 163 [sty appendFormat:@"text-decoration: %@; ", ip? @"line-through" : @"none"]; 164 break; 165 case tag_fn: 166 sv(); 167 [sty appendFormat:@"font-family: %@; ", sp]; 168 break; 169 case tag_fs: 170 fv(); 171 //this is wrong, see GetWinFontSizeScale() 172 [sty appendFormat:@"font-size: %fpt; ", fp * (72./96.)]; 173 break; 174 case tag_1c: 175 cv(); 176 [sty appendFormat:@"color: #%0.9X; ", ip]; 177 break; 178 case tag_4c: 179 cv(); 180 [sty appendFormat:@"text-shadow: #%0.9X %fpx %fpx 0; ", ip, div->styleLine->shadowDist*2., div->styleLine->shadowDist*2.]; 181 break; 182 default: 183 NSLog(@"unimplemented tag type %d",tag); 184 } 185 } 186 187 -(void)htmlifyDivArray:(NSArray*)divs 188 { 189 int div_count = [divs count], i; 190 for (i = 0; i < div_count; i++) { 191 SubRenderDiv *div = [divs objectAtIndex:i]; 192 int j, spancount = [div->spans count], spans = 1, close_div = 0; 193 194 if (div->positioned) { 195 [html appendFormat:@"<div style=\"top: %fpx; left: %fpx; position: absolute\">", div->posY, div->posX]; 196 close_div = 1; 197 } 198 199 [html appendFormat:@"<span class=\"%@\">", div->styleLine->name]; 200 201 for (j = 0; j < spancount; j++) { 202 SubRenderSpan *span = [div->spans objectAtIndex:j]; 203 NSMutableString *ex = span->ex; 204 int exl = [ex length]; 205 206 if (exl) {[html appendFormat:@"<span style=\"%@\">",ex]; spans++;} 207 [html appendString:htmlfilter([div->text substringWithRange:NSMakeRange(span->offset, ((j == (spancount-1)) ? [div->text length] : ((SubRenderSpan*)[div->spans objectAtIndex:j+1])->offset) - span->offset)])]; 208 } 209 210 while (spans--) [html appendString:@"</span>"]; 211 if (close_div) [html appendString:@"</div>"]; 212 [html appendString:@"\n"]; 213 } 214 } 215 216 -(void)addSub:(SubLine*)sl 217 { 218 unichar *ubuf = malloc(sizeof(unichar) * [sl->line length]); 219 NSArray *divs = SubParsePacket(sl->line, sc, self); 220 free(ubuf); 221 NSMutableArray *top = [NSMutableArray array], *bot = [NSMutableArray array], *abs = [NSMutableArray array]; 222 int div_count = [divs count], i; 223 224 [html appendString:@"<div class=\"screen\">\n"]; 225 226 for (i = 0; i < div_count; i++) { 227 SubRenderDiv *div = [divs objectAtIndex:i]; 228 229 if (div->positioned) [abs addObject:div]; else if (div->alignV == kSubAlignmentTop) [top addObject:div]; else [bot insertObject:div atIndex:0]; 230 } 231 232 if ([top count]) { 233 [html appendString:@"<div class=\"top\">\n"]; 234 [self htmlifyDivArray:top]; 235 [html appendString:@"</div>\n"]; 236 } 237 238 if ([bot count]) { 239 [html appendString:@"<div class=\"bottom\">\n"]; 240 [self htmlifyDivArray:bot]; 241 [html appendString:@"</div>\n"]; 242 } 243 244 [self htmlifyDivArray:abs]; 245 246 [html appendString:@"</div>\n"]; 247 248 [html appendString:@"<br>\n"]; 249 } 250 251 -(void)endOfFile 252 { 253 [html appendString:@"</body></html>\n"]; 254 } 255 @end 26 extern CGContextRef CGPSContextCreateWithURL(CFURLRef url, const CGRect *mediaBox, CFDictionaryRef auxiliaryInfo); 27 extern void CGPSContextClose(CGContextRef c); 256 28 257 29 int main(int argc, char *argv[]) 258 30 { 259 if (argc != 2)31 if (argc != 3) 260 32 return 1; 261 33 262 34 NSAutoreleasePool *outer_pool = [[NSAutoreleasePool alloc] init]; 263 35 SubContext *sc; SubSerializer *ss = [[SubSerializer alloc] init]; 264 SubHTMLExporter *htm = [[SubHTMLExporter alloc] init];265 NSAutoreleasePool *inner_pool = [[NSAutoreleasePool alloc] init];36 NSString *inFile = [NSString stringWithUTF8String:argv[1]], *outDir = [NSString stringWithUTF8String:argv[2]]; 37 int i = 0; 266 38 267 //start of lameness 268 //it should only have to call subparsessafile here, or something 269 NSString *header = LoadSSAFromPath([NSString stringWithUTF8String:argv[1]], ss); 39 //loading copied from ssa2html, still duplicated 40 NSString *header = LoadSSAFromPath(inFile, ss); 270 41 [ss setFinished:YES]; 271 42 272 43 NSDictionary *headers; 273 44 NSArray *styles; 274 45 SubParseSSAFile(header, &headers, &styles, NULL); 275 sc = [[SubContext alloc] initWithHeaders:headers styles:styles delegate:htm]; 276 //end(?) of lameness 277 //other part of lameness: some sub objects are autoreleased instead of manually released 278 //fix this so inner_pool can be deleted 279 280 [htm endOfHead]; 281 46 sc = [[SubContext alloc] initWithHeaders:headers styles:styles delegate:NULL]; 47 int width = sc->resX, height = sc->resY; 48 CGRect rect = CGRectMake(0, 0, width, height); 49 SubtitleRendererPtr s = SubInitSSA((char*)[header UTF8String], [header length], width, height); 50 282 51 while (![ss isEmpty]) { 52 NSAutoreleasePool *inner_pool = [[NSAutoreleasePool alloc] init]; 283 53 SubLine *sl = [ss getSerializedPacket]; 284 if ([sl->line length] == 1) continue; 285 286 [htm addSub:sl]; 54 if ([sl->line length] > 1) { 55 NSString *pdf = [outDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%d.pdf", i]]; 56 CGContextRef pdfC = CGPDFContextCreateWithURL((CFURLRef)[NSURL fileURLWithPath:pdf], &rect, NULL); 57 CGContextBeginPage(pdfC, NULL); 58 SubRenderPacket(s, pdfC, (CFStringRef)sl->line, width, height); 59 CGContextEndPage(pdfC); 60 CGContextRelease(pdfC); 61 62 NSString *ps = [outDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%d.eps", i]]; 63 CGContextRef psC = CGPSContextCreateWithURL((CFURLRef)[NSURL fileURLWithPath:ps], &rect, NULL); 64 CGContextBeginPage(psC, NULL); 65 SubRenderPacket(s, psC, (CFStringRef)sl->line, width, height); 66 CGContextEndPage(psC); 67 CGContextRelease(psC); 68 69 i++; 70 } 71 [inner_pool release]; 287 72 } 288 73 289 [htm endOfFile];290 291 printf([htm->html UTF8String]);292 [inner_pool release];293 74 [ss release]; 294 [htm release];295 75 [outer_pool release]; 296 76 trunk/TextSubCodec.c
r1108 r1122 261 261 GetImageDescriptionExtension(p->imageDescription,&ssaheader,kSubFormatSSA,1); 262 262 263 glob->ssa = SubInit ForSSA(*ssaheader, GetHandleSize(ssaheader), (**p->imageDescription).width, (**p->imageDescription).height);263 glob->ssa = SubInitSSA(*ssaheader, GetHandleSize(ssaheader), (**p->imageDescription).width, (**p->imageDescription).height); 264 264 } 265 265 } … … 335 335 336 336 SubRenderPacket(glob->ssa,c,buf,myDrp->width,myDrp->height); 337 338 #if 0339 {340 CFURLRef url = CFURLCreateFromFileSystemRepresentation(NULL, "/subtitle.pdf", strlen("/subtitle.pdf"), 0);341 CGRect rect = CGRectMake(0,0, myDrp->width, myDrp->height);342 CGContextRef pc = CGPDFContextCreateWithURL(url, &rect, NULL);343 337 344 CGPDFContextBeginPage(pc, NULL);345 SubRenderPacket(glob->ssa,pc,buf,myDrp->width,myDrp->height);346 CGPDFContextEndPage(pc);347 CGContextRelease(pc);348 CFRelease(url);349 }350 #endif351 352 338 CFRelease(buf); 353 339
