Changeset 26731
- Timestamp:
- 2013-01-16T18:56:21+13:00 (11 years ago)
- Location:
- gs3-extensions/html-to-expeditee/trunk/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
gs3-extensions/html-to-expeditee/trunk/src/perllib/CssStyleToExpAttr.pm
r26729 r26731 352 352 my $exp_font_size = undef; 353 353 354 355 354 if ($css_font_size =~ m/^(\d+(?:\.\d*))px$/) { 356 355 $exp_font_size = int($1); 357 } 356 }else{ 357 #FF rounds sizes, e.g. 16.13px will just be 16px. 358 my $end_index = length($css_font_size) - 2; 359 $exp_font_size = substr($css_font_size,0,$end_index); 360 } 358 361 359 362 return $exp_font_size; … … 365 368 my $exp_font_face = undef; 366 369 367 if(lc($css_font_face) eq "bold"){ 370 #Firefox uses '700' instead of 'bold' for font-weight. 371 if(lc($css_font_face) eq "bold" || $css_font_face eq "700"){ 368 372 $exp_font_face = "b"; 369 }elsif(lc($css_font_face) eq "italic"){ #for now - also need to take into account italic and italic bold.373 }elsif(lc($css_font_face) eq "italic"){ 370 374 $exp_font_face = "i"; 371 }elsif(lc($css_font_face) eq "bold-italic" ){375 }elsif(lc($css_font_face) eq "bold-italic" || $css_font_face eq "700-italic"){ 372 376 $exp_font_face = "p"; 373 377 }else{ 374 378 $exp_font_face = "r"; 375 379 } 376 380 377 381 return $exp_font_face; 378 382 } -
gs3-extensions/html-to-expeditee/trunk/src/perllib/ExpediteeFrameIO.pm
r26730 r26731 70 70 sub convertStyleToAttr 71 71 { 72 my ($css_attr ) = @_;72 my ($css_attr,$compute_font) = @_; 73 73 74 74 my $exp_attr = {}; … … 79 79 my $exp_font_size = "18"; 80 80 81 # if (defined $css_attr->{'font-family'}) { 82 # $font_family = $font_family_lookup->[$css_attr->{'font-family'}]; 83 # } 84 85 if (defined $css_attr->{'font-size'}) { 81 if(defined $compute_font){ 82 if($compute_font eq "true"){ 83 84 if (defined $css_attr->{'font-size'}) { 86 85 87 my $css_font_size = $css_attr->{'font-size'}; 88 $exp_font_size = CssStyleToExpAttr::convert_font_size($css_font_size); 89 90 } 91 92 if(defined $css_attr->{'font-family'}){ 93 my $obtain_font_family = $css_attr->{'font-family'}; 94 my $new_exp_font_family = CssStyleToExpAttr::convert_font_family($obtain_font_family); 95 96 if(defined $new_exp_font_family){ 97 $exp_font_family = $new_exp_font_family; 86 my $css_font_size = $css_attr->{'font-size'}; 87 my $new_exp_font_size = CssStyleToExpAttr::convert_font_size($css_font_size); 88 89 if(defined $new_exp_font_size){ 90 $exp_font_size = $new_exp_font_size; 91 } 92 } 93 94 if(defined $css_attr->{'font-family'}){ 95 my $obtain_font_family = $css_attr->{'font-family'}; 96 my $new_exp_font_family = CssStyleToExpAttr::convert_font_family($obtain_font_family); 97 98 if(defined $new_exp_font_family){ 99 $exp_font_family = $new_exp_font_family; 100 } 101 } 102 103 #obtain font style/weight - bold, italic or bold-italic. 104 105 if(defined $css_attr->{'font-style'}){ 106 my $css_font_style = $css_attr->{'font-style'}; 107 my $new_exp_font_face = CssStyleToExpAttr::convert_font_face($css_font_style); 108 109 if(defined $new_exp_font_face){ 110 $exp_font_face = $new_exp_font_face; 111 } 112 } 113 114 if(defined $css_attr->{'font-weight'}){ 115 my $css_font_face = $css_attr->{'font-weight'}; 116 my $new_exp_font_face = CssStyleToExpAttr::convert_font_face($css_font_face); 117 118 if(defined $new_exp_font_face){ 119 $exp_font_face = $new_exp_font_face; 120 } 121 } 122 123 if(defined $css_attr->{'font-style'} && defined $css_attr->{'font-weight'}){ 124 my $font_face_param = $css_attr->{'font-weight'}.'-'.$css_attr->{'font-style'}; 125 my $new_exp_font_face = CssStyleToExpAttr::convert_font_face($font_face_param); 126 127 if(defined $new_exp_font_face){ 128 $exp_font_face = $new_exp_font_face; 129 } 130 } 131 132 # color 133 if(defined $css_attr->{'color'}){ 134 my $css_color = $css_attr->{'color'}; 135 136 my $exp_color = CssStyleToExpAttr::convert_color($css_color); 137 138 $exp_attr->{'d'} = $exp_color; 139 } 98 140 } 99 141 } 100 142 101 my $css_font_style; 102 my $css_font_face; 103 104 if(defined $css_attr->{'font-style'}){ 105 $css_font_style = $css_attr->{'font-style'}; 106 $exp_font_face = CssStyleToExpAttr::convert_font_face($css_font_style); 107 } 108 109 if(defined $css_attr->{'font-weight'}){ 110 $css_font_face = $css_attr->{'font-weight'}; 111 $exp_font_face = CssStyleToExpAttr::convert_font_face($css_font_face); 112 } 113 114 if(defined $css_attr->{'font-style'} && defined $css_attr->{'font-weight'}){ 115 my $font_face_param = $css_attr->{'font-weight'}.'-'.$css_attr->{'font-style'}; 116 $exp_font_face = CssStyleToExpAttr::convert_font_face($font_face_param); 117 } 118 119 $exp_attr->{'f'} = $exp_font_family.$exp_font_face.$exp_font_size; 143 $exp_attr->{'f'} = $exp_font_family.$exp_font_face.$exp_font_size; 120 144 121 145 # background color 122 123 124 146 if (defined $css_attr->{'background-color'}) { 125 147 my $css_color = $css_attr->{'background-color'}; … … 129 151 $exp_attr->{'e'} = $exp_color; 130 152 } 131 153 154 155 132 156 return $exp_attr; 133 157 } … … 251 275 $attr_copy{'P'} = "$x $y"; 252 276 $attr_copy{'T'} = $text; 253 $attr_copy{'w'} = "-$w" if (defined $w); 277 #$attr_copy{'w'} = "-$w" if (defined $w); 278 $attr_copy{'w'} = "$w" if (defined $w); 254 279 255 280 return $self->_addItem("T",\%attr_copy); … … 534 559 $self->writeStatisticsSection(); 535 560 536 537 538 561 close(FOUT); 539 562 $status = 1; … … 550 573 { 551 574 my $self = shift @_; 552 my ($html_node ) = @_;575 my ($html_node,$compute_font) = @_; 553 576 554 577 my $type = $html_node->{'type'}; 555 578 556 579 if ($type eq "rect") { … … 561 584 my $yt = $rect->{'yt'}; 562 585 my $yb = $rect->{'yb'}; 563 586 564 587 my $attr = convertStyleToAttr($html_node->{'style'}); 565 588 … … 606 629 } 607 630 elsif ($type eq "text") { 608 631 609 632 my $text = $html_node->{'text'}; 610 633 611 634 my $x = $html_node->{'xl'}; 612 635 my $y = $html_node->{'yt'}; 613 my $w = $html_node->{'xr'} - $x +1; 614 615 my $attr = convertStyleToAttr($html_node->{'style'}); 636 #my $w = $html_node->{'xr'} - $x +1; 637 638 my $w = undef; 639 640 if(defined $html_node->{'width'}){ 641 $w = $html_node->{'width'} - 5; #take away 5px for extra space. 642 } 643 644 my $attr = convertStyleToAttr($html_node->{'style'},$compute_font); 616 645 617 646 # fudge factor for now (based on default font size used) … … 630 659 my $childNodes = $html_node->{'childNodes'}; 631 660 foreach my $child_node (@$childNodes) { 632 $self->buildFrame($child_node );661 $self->buildFrame($child_node,$compute_font); 633 662 } 634 663 } -
gs3-extensions/html-to-expeditee/trunk/src/perllib/cgiactions/HtmlToExpediteeAction.pm
r26597 r26731 50 50 { 51 51 "generate-frame" => { 'compulsory-args' => [ "fn", "json" ], 52 'optional-args' => ["assoc" ] },52 'optional-args' => ["assoc", "compute-font"] }, 53 53 }; 54 54 … … 80 80 81 81 my $assoc = $self->{'assoc'}; 82 82 83 my $compute_font = $self->{'compute-font'}; 84 print STDERR "Wil send compute_font... $compute_font\n\n"; 85 83 86 # no need to lock collection (??), the operation is read only 84 87 … … 95 98 my $expeditee_frame_io = new ExpediteeFrameIO($output_dir); 96 99 97 $expeditee_frame_io->buildFrame($exp_frame_tree );100 $expeditee_frame_io->buildFrame($exp_frame_tree,$compute_font); 98 101 99 102 if ($expeditee_frame_io->saveFrame("$fn.exp",$assoc)) { -
gs3-extensions/html-to-expeditee/trunk/src/src/cgi-bin/html-to-expeditee.pl.in
r26728 r26731 62 62 63 63 <input value="$site" name="site" id="site" type="hidden"> 64 <input value="Go" id="go" 65 class="ui-button ui-widget ui-state-default ui-corner-all" 66 type="submit"> 64 65 <p> 66 <input type="checkbox" id="checkBoxBrowsing" name="generate_browsing" value="generate_browsing">Generate Browsing Frameset<br/> 67 </p> 68 69 <p style="font-weight: bold;">Extra Expeditee Frame Output Options:</p> 70 <input type="checkbox" id="checkBoxFont" name="compute_font" value="compute_font">Compute Font<br/> 71 <input type="checkbox" id="checkBoxWidth" name="compute_width" value="compute_width">Compute Width<br/> 72 73 <p><input value="Go" id="go" class="ui-button ui-widget ui-state-default ui-corner-all" type="submit"><p> 67 74 68 75 </form> … … 70 77 var docOIDs = []; 71 78 var numDocOIDs; 72 79 var compute_font = false; 80 var compute_width = false; 81 var generate_browsing = false; //whether to generate a matching browsing frameset 82 73 83 \$(function() { 74 84 \$('#progress').progressbar(); … … 89 99 cl = "CL" + cl; 90 100 } 91 101 102 compute_font = document.getElementById("checkBoxFont").checked; 103 compute_width = document.getElementById("checkBoxWidth").checked; 104 105 generate_browsing = document.getElementById("checkBoxBrowsing").checked; 106 92 107 var gs2=$isGSDL2; 93 108 … … 102 117 url += "&excerptid=gs_content"; 103 118 } 119 120 console.log("*** CHECKING URL: " + url); 104 121 105 122 /* processing animation */ … … 227 244 if(frameNum === null){ 228 245 frameNum = iter; 229 console.log("no frameNum found, use iter: " + frameNum);230 }else{231 console.log("frameNum metadata found: " + frameNum);232 246 } 233 247 … … 252 266 } 253 267 254 var expFrameTree = htmlToExpeditee(gsContent );268 var expFrameTree = htmlToExpeditee(gsContent,compute_font,compute_width); 255 269 256 270 var expFrame = JSON.stringify(expFrameTree); 257 258 console.log(expFrame); 259 271 //console.log(expFrame); 260 272 //alert(expFrame); 261 273 … … 277 289 params += "&assoc=" + assoc; 278 290 } 291 292 params += "&compute-font=" + compute_font; 279 293 280 294 var clHtml = urlPostSync(url,params); … … 417 431 my $collect = $gsdl_cgi->clean_param("collect"); 418 432 my $cl = $gsdl_cgi->clean_param("cl"); 419 433 420 434 # Establish collect_dir using defining 'site' along the way if GS3 421 435 -
gs3-extensions/html-to-expeditee/trunk/src/src/js/html-to-expeditee.js
r26729 r26731 7 7 var font_weight; 8 8 var font_style; 9 10 var compute_font = false; 11 var compute_width = false; 9 12 10 13 Element.prototype.getElementWidth = function() { … … 105 108 106 109 107 function htmlToExpeditee(node) 108 { 110 function htmlToExpeditee(node,compFont,compWidth) 111 { 112 compute_font = compFont; 113 compute_width = compWidth; 114 109 115 var nodePos = getElementPosition(node); 110 116 var parentStyle = node.getAttribute('style'); 111 117 112 118 //Use these as default values if font info can't be found for text items. 113 font_family = getStyle(node,'font-family'); 114 font_size = getStyle(node,'font-size'); 115 font_color = getStyle(node,'color'); 116 117 console.log("Retrieving node: " + node); 118 119 console.log("Retrieving font family: " + font_family); 120 console.log("Retrieving font size: " + font_size); 121 console.log("Retrieving font color: " + font_color); 119 //and only if the user wants the font computed (otherwise use Expeditee defaults). 120 if(compute_font){ 121 font_family = getStyle(node,'font-family'); 122 font_size = getStyle(node,'font-size'); 123 font_color = getStyle(node,'color'); 124 125 /*console.log("Retrieving node: " + node); 126 127 console.log("Retrieving font family: " + font_family); 128 console.log("Retrieving font size: " + font_size); 129 console.log("Retrieving font color: " + font_color);*/ 130 } 122 131 123 132 var pxl = nodePos.xl; … … 156 165 if (parent != null) { 157 166 158 //obtain font info for text nodes from their parent nodes. 159 var new_font_family = getStyle(parent,"font-family"); 160 var new_font_size = getStyle(parent,"font-size"); 161 var new_font_color = getStyle(parent,"color"); 162 163 var new_font_weight = getStyle(parent,"font-weight"); 164 var new_font_style = getStyle(parent,"font-style"); 165 166 if(new_font_family !== undefined && new_font_family !== null) 167 font_family = new_font_family; 168 169 if(new_font_size !== undefined && new_font_size !== null) 170 font_size = new_font_size; 171 172 if(new_font_color !== undefined && new_font_color !== null) 173 font_color = new_font_color; 167 if(compute_font){ 168 //obtain font info for text nodes from their parent nodes. 169 var new_font_family = getStyle(parent,"font-family"); 170 var new_font_size = getStyle(parent,"font-size"); 171 var new_font_color = getStyle(parent,"color"); 172 173 var new_font_weight = getStyle(parent,"font-weight"); 174 var new_font_style = getStyle(parent,"font-style"); 175 176 if(new_font_family !== undefined && new_font_family !== null) 177 font_family = new_font_family; 178 179 if(new_font_size !== undefined && new_font_size !== null) 180 font_size = new_font_size; 181 182 if(new_font_color !== undefined && new_font_color !== null) 183 font_color = new_font_color; 174 184 175 if(new_font_weight !== undefined && new_font_weight !== null) 176 font_weight = new_font_weight; 185 //TODO: if parent node is a <b> element, then set style["font-weight"] to be "bold". 186 if(new_font_weight !== undefined && new_font_weight !== null) 187 font_weight = new_font_weight; 177 188 178 if(new_font_style !== undefined && new_font_style !== null) 179 font_style = new_font_style; 180 181 var data = parent.attributes["data"]; 182 183 if (data != null) { 189 if(new_font_style !== undefined && new_font_style !== null) 190 font_style = new_font_style; 191 192 var style = {}; 193 style["font-family"] = font_family; 194 style["font-size"] = font_size; 195 style["color"] = font_color; 196 style["font-weight"] = font_weight; 197 style["font-style"] = font_style; 198 199 jsonNode.style = style; 200 } 201 202 if(compute_width){ 203 var parentPos = getElementPosition(parent); 204 var parentWidth = parentPos.xr - parentPos.xl; 205 206 /*console.log("parent.xl: " + parentPos.xl); 207 console.log("parent.xr: " + parentPos.xr); 208 console.log("parent width: " + parentWidth);*/ 209 210 jsonNode.width = parentWidth; 211 } 212 213 var data = parent.attributes["data"]; 214 215 if (data != null) { 184 216 jsonNode.data = data.value; 185 } 186 187 var style = {}; 188 style["font-family"] = font_family; 189 style["font-size"] = font_size; 190 style["color"] = font_color; 191 style["font-weight"] = font_weight; 192 style["font-style"] = font_style; 193 194 //TODO: if parent node is a <b> element, then set style["font-weight"] to be "bold". 195 196 jsonNode.style = style; 217 } 218 219 197 220 } 198 221 }
Note:
See TracChangeset
for help on using the changeset viewer.