Ignore:
Timestamp:
10/08/08 10:56:42 (5 years ago)
Author:
jeroen
Message:

fixed a few small bugs (resizing), updated the pdf and added the parsers for TT and SRT

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/4.2/com/jeroenwijering/parsers/TTParser.as

    r12 r79  
    11/** 
    2 * Parse a TimedText XML and return a rich array. 
     2* Parse a TimedText XML and return an array of captions. 
     3* 
     4* The entries in the array look like: 
     5* []['begin'] 
     6* []['end'] 
     7* []['text'] 
     8* 
    39**/ 
    410package com.jeroenwijering.parsers { 
     
    1117 
    1218 
    13         /** All supported styling elements. **/ 
    14         public static var STYLING:Object = { 
    15                 'id':0, 
    16                 'backgroundColor':'000000', 
    17                 'color':'FFFFFF', 
    18                 'displayAlign':'after', 
    19                 'fontFamily':'Arial', 
    20                 'fontSize':12, 
    21                 'fontStyle':false, 
    22                 'fontWeight':false, 
    23                 'opacity':0, 
    24                 'padding':20, 
    25                 'textAlign:':'center' 
    26         }; 
    27         /** All supported paragraph elements. **/ 
     19        /** The supported paragraph elements. **/ 
    2820        private static var ELEMENTS:Object = { 
    2921                'begin':undefined, 
    3022                'dur':undefined, 
    3123                'end':undefined, 
    32                 'style':undefined, 
    3324                'text':undefined 
    34         }; 
    35         /** Default style ID **/ 
    36         private static var style:Number; 
    37  
    38  
    39         /** Parse the styling head. **/ 
    40         public static function parseStyles(dat:XML):Array { 
    41                 var arr = new Array(TTParser.STYLING); 
    42                 for each (var i in dat.children()[0].children()) { 
    43                         if (i.localName() == 'styling') { 
    44                                 for each (var j in i.children()) { 
    45                                         var obj = TTParser.parseStyle(j); 
    46                                         arr[obj.id] = obj; 
    47                                 } 
    48                         } 
    49                 } 
    50                 return arr; 
    51         }; 
    52  
    53  
    54         /** Parse a single style definition. **/ 
    55         private static function parseStyle(dat:XML):Object { 
    56                 var obj = new Object(); 
    57                 for(var i in TTParser.STYLING) { 
    58                         obj[i] = TTParser.STYLING[i]; 
    59                 } 
    60                 for (var j=0; j<dat.attributes().length(); j++) { 
    61                         obj[dat.attributes()[j].localName()] = dat.attributes()[j]; 
    62                 } 
    63                 return obj; 
    6425        }; 
    6526 
     
    6930                var arr = new Array(); 
    7031                var div = dat.children()[1].children()[0]; 
    71                 if(dat.children()[1].@style > 0) { 
    72                         TTParser.style = dat.children()[1].@style; 
    73                 } else if(div.@style > 0) { 
    74                         TTParser.style = div.@style; 
    75                 } 
    7632                for each (var i in div.children()) { 
    7733                        if(i.localName() == 'p') { 
     
    8945                        dur:Strings.seconds(dat.@dur), 
    9046                        end:Strings.seconds(dat.@end), 
    91                         text:Strings.strip(dat.children()), 
    92                         style:dat.@style.toString() 
     47                        text:dat.children().toString() 
    9348                }; 
    9449                if(obj['dur']) { 
    9550                        obj['end'] = obj['begin'] + obj['dur']; 
    9651                        delete obj['dur']; 
    97                 } 
    98                 if(obj['style'] == '') { 
    99                         obj['style'] = TTParser.style; 
    10052                } 
    10153                return obj; 
Note: See TracChangeset for help on using the changeset viewer.