1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.fontbox.ttf; 18 19 import java.io.IOException; 20 21 /** 22 * A table in a true type font. 23 * 24 * @author Ben Litchfield (ben@benlitchfield.com) 25 * @version $Revision: 1.1 $ 26 */ 27 public class OS2WindowsMetricsTable extends TTFTable 28 { 29 30 /** 31 * Weight class constant. 32 */ 33 public static final int WEIGHT_CLASS_THIN = 100; 34 /** 35 * Weight class constant. 36 */ 37 public static final int WEIGHT_CLASS_ULTRA_LIGHT = 200; 38 /** 39 * Weight class constant. 40 */ 41 public static final int WEIGHT_CLASS_LIGHT = 300; 42 /** 43 * Weight class constant. 44 */ 45 public static final int WEIGHT_CLASS_NORMAL = 400; 46 /** 47 * Weight class constant. 48 */ 49 public static final int WEIGHT_CLASS_MEDIUM = 500; 50 /** 51 * Weight class constant. 52 */ 53 public static final int WEIGHT_CLASS_SEMI_BOLD = 600; 54 /** 55 * Weight class constant. 56 */ 57 public static final int WEIGHT_CLASS_BOLD = 700; 58 /** 59 * Weight class constant. 60 */ 61 public static final int WEIGHT_CLASS_EXTRA_BOLD = 800; 62 /** 63 * Weight class constant. 64 */ 65 public static final int WEIGHT_CLASS_BLACK = 900; 66 67 /** 68 * Width class constant. 69 */ 70 public static final int WIDTH_CLASS_ULTRA_CONDENSED = 1; 71 /** 72 * Width class constant. 73 */ 74 public static final int WIDTH_CLASS_EXTRA_CONDENSED = 2; 75 /** 76 * Width class constant. 77 */ 78 public static final int WIDTH_CLASS_CONDENSED = 3; 79 /** 80 * Width class constant. 81 */ 82 public static final int WIDTH_CLASS_SEMI_CONDENSED = 4; 83 /** 84 * Width class constant. 85 */ 86 public static final int WIDTH_CLASS_MEDIUM = 5; 87 /** 88 * Width class constant. 89 */ 90 public static final int WIDTH_CLASS_SEMI_EXPANDED = 6; 91 /** 92 * Width class constant. 93 */ 94 public static final int WIDTH_CLASS_EXPANDED = 7; 95 /** 96 * Width class constant. 97 */ 98 public static final int WIDTH_CLASS_EXTRA_EXPANDED = 8; 99 /** 100 * Width class constant. 101 */ 102 public static final int WIDTH_CLASS_ULTRA_EXPANDED = 9; 103 104 /** 105 * Family class constant. 106 */ 107 public static final int FAMILY_CLASS_NO_CLASSIFICATION = 0; 108 /** 109 * Family class constant. 110 */ 111 public static final int FAMILY_CLASS_OLDSTYLE_SERIFS = 1; 112 /** 113 * Family class constant. 114 */ 115 public static final int FAMILY_CLASS_TRANSITIONAL_SERIFS = 2; 116 /** 117 * Family class constant. 118 */ 119 public static final int FAMILY_CLASS_MODERN_SERIFS = 3; 120 /** 121 * Family class constant. 122 */ 123 public static final int FAMILY_CLASS_CLAREDON_SERIFS = 4; 124 /** 125 * Family class constant. 126 */ 127 public static final int FAMILY_CLASS_SLAB_SERIFS = 5; 128 /** 129 * Family class constant. 130 */ 131 public static final int FAMILY_CLASS_FREEFORM_SERIFS = 7; 132 /** 133 * Family class constant. 134 */ 135 public static final int FAMILY_CLASS_SANS_SERIF = 8; 136 /** 137 * Family class constant. 138 */ 139 public static final int FAMILY_CLASS_ORNAMENTALS = 9; 140 /** 141 * Family class constant. 142 */ 143 public static final int FAMILY_CLASS_SCRIPTS = 10; 144 /** 145 * Family class constant. 146 */ 147 public static final int FAMILY_CLASS_SYMBOLIC = 12; 148 149 /** 150 * @return Returns the achVendId. 151 */ 152 public String getAchVendId() 153 { 154 return achVendId; 155 } 156 /** 157 * @param achVendIdValue The achVendId to set. 158 */ 159 public void setAchVendId(String achVendIdValue) 160 { 161 this.achVendId = achVendIdValue; 162 } 163 /** 164 * @return Returns the averageCharWidth. 165 */ 166 public short getAverageCharWidth() 167 { 168 return averageCharWidth; 169 } 170 /** 171 * @param averageCharWidthValue The averageCharWidth to set. 172 */ 173 public void setAverageCharWidth(short averageCharWidthValue) 174 { 175 this.averageCharWidth = averageCharWidthValue; 176 } 177 /** 178 * @return Returns the codePageRange1. 179 */ 180 public long getCodePageRange1() 181 { 182 return codePageRange1; 183 } 184 /** 185 * @param codePageRange1Value The codePageRange1 to set. 186 */ 187 public void setCodePageRange1(long codePageRange1Value) 188 { 189 this.codePageRange1 = codePageRange1Value; 190 } 191 /** 192 * @return Returns the codePageRange2. 193 */ 194 public long getCodePageRange2() 195 { 196 return codePageRange2; 197 } 198 /** 199 * @param codePageRange2Value The codePageRange2 to set. 200 */ 201 public void setCodePageRange2(long codePageRange2Value) 202 { 203 this.codePageRange2 = codePageRange2Value; 204 } 205 /** 206 * @return Returns the familyClass. 207 */ 208 public short getFamilyClass() 209 { 210 return familyClass; 211 } 212 /** 213 * @param familyClassValue The familyClass to set. 214 */ 215 public void setFamilyClass(short familyClassValue) 216 { 217 this.familyClass = familyClassValue; 218 } 219 /** 220 * @return Returns the firstCharIndex. 221 */ 222 public int getFirstCharIndex() 223 { 224 return firstCharIndex; 225 } 226 /** 227 * @param firstCharIndexValue The firstCharIndex to set. 228 */ 229 public void setFirstCharIndex(int firstCharIndexValue) 230 { 231 this.firstCharIndex = firstCharIndexValue; 232 } 233 /** 234 * @return Returns the fsSelection. 235 */ 236 public int getFsSelection() 237 { 238 return fsSelection; 239 } 240 /** 241 * @param fsSelectionValue The fsSelection to set. 242 */ 243 public void setFsSelection(int fsSelectionValue) 244 { 245 this.fsSelection = fsSelectionValue; 246 } 247 /** 248 * @return Returns the fsType. 249 */ 250 public short getFsType() 251 { 252 return fsType; 253 } 254 /** 255 * @param fsTypeValue The fsType to set. 256 */ 257 public void setFsType(short fsTypeValue) 258 { 259 this.fsType = fsTypeValue; 260 } 261 /** 262 * @return Returns the lastCharIndex. 263 */ 264 public int getLastCharIndex() 265 { 266 return lastCharIndex; 267 } 268 /** 269 * @param lastCharIndexValue The lastCharIndex to set. 270 */ 271 public void setLastCharIndex(int lastCharIndexValue) 272 { 273 this.lastCharIndex = lastCharIndexValue; 274 } 275 /** 276 * @return Returns the panose. 277 */ 278 public byte[] getPanose() 279 { 280 return panose; 281 } 282 /** 283 * @param panoseValue The panose to set. 284 */ 285 public void setPanose(byte[] panoseValue) 286 { 287 this.panose = panoseValue; 288 } 289 /** 290 * @return Returns the strikeoutPosition. 291 */ 292 public short getStrikeoutPosition() 293 { 294 return strikeoutPosition; 295 } 296 /** 297 * @param strikeoutPositionValue The strikeoutPosition to set. 298 */ 299 public void setStrikeoutPosition(short strikeoutPositionValue) 300 { 301 this.strikeoutPosition = strikeoutPositionValue; 302 } 303 /** 304 * @return Returns the strikeoutSize. 305 */ 306 public short getStrikeoutSize() 307 { 308 return strikeoutSize; 309 } 310 /** 311 * @param strikeoutSizeValue The strikeoutSize to set. 312 */ 313 public void setStrikeoutSize(short strikeoutSizeValue) 314 { 315 this.strikeoutSize = strikeoutSizeValue; 316 } 317 /** 318 * @return Returns the subscriptXOffset. 319 */ 320 public short getSubscriptXOffset() 321 { 322 return subscriptXOffset; 323 } 324 /** 325 * @param subscriptXOffsetValue The subscriptXOffset to set. 326 */ 327 public void setSubscriptXOffset(short subscriptXOffsetValue) 328 { 329 this.subscriptXOffset = subscriptXOffsetValue; 330 } 331 /** 332 * @return Returns the subscriptXSize. 333 */ 334 public short getSubscriptXSize() 335 { 336 return subscriptXSize; 337 } 338 /** 339 * @param subscriptXSizeValue The subscriptXSize to set. 340 */ 341 public void setSubscriptXSize(short subscriptXSizeValue) 342 { 343 this.subscriptXSize = subscriptXSizeValue; 344 } 345 /** 346 * @return Returns the subscriptYOffset. 347 */ 348 public short getSubscriptYOffset() 349 { 350 return subscriptYOffset; 351 } 352 /** 353 * @param subscriptYOffsetValue The subscriptYOffset to set. 354 */ 355 public void setSubscriptYOffset(short subscriptYOffsetValue) 356 { 357 this.subscriptYOffset = subscriptYOffsetValue; 358 } 359 /** 360 * @return Returns the subscriptYSize. 361 */ 362 public short getSubscriptYSize() 363 { 364 return subscriptYSize; 365 } 366 /** 367 * @param subscriptYSizeValue The subscriptYSize to set. 368 */ 369 public void setSubscriptYSize(short subscriptYSizeValue) 370 { 371 this.subscriptYSize = subscriptYSizeValue; 372 } 373 /** 374 * @return Returns the superscriptXOffset. 375 */ 376 public short getSuperscriptXOffset() 377 { 378 return superscriptXOffset; 379 } 380 /** 381 * @param superscriptXOffsetValue The superscriptXOffset to set. 382 */ 383 public void setSuperscriptXOffset(short superscriptXOffsetValue) 384 { 385 this.superscriptXOffset = superscriptXOffsetValue; 386 } 387 /** 388 * @return Returns the superscriptXSize. 389 */ 390 public short getSuperscriptXSize() 391 { 392 return superscriptXSize; 393 } 394 /** 395 * @param superscriptXSizeValue The superscriptXSize to set. 396 */ 397 public void setSuperscriptXSize(short superscriptXSizeValue) 398 { 399 this.superscriptXSize = superscriptXSizeValue; 400 } 401 /** 402 * @return Returns the superscriptYOffset. 403 */ 404 public short getSuperscriptYOffset() 405 { 406 return superscriptYOffset; 407 } 408 /** 409 * @param superscriptYOffsetValue The superscriptYOffset to set. 410 */ 411 public void setSuperscriptYOffset(short superscriptYOffsetValue) 412 { 413 this.superscriptYOffset = superscriptYOffsetValue; 414 } 415 /** 416 * @return Returns the superscriptYSize. 417 */ 418 public short getSuperscriptYSize() 419 { 420 return superscriptYSize; 421 } 422 /** 423 * @param superscriptYSizeValue The superscriptYSize to set. 424 */ 425 public void setSuperscriptYSize(short superscriptYSizeValue) 426 { 427 this.superscriptYSize = superscriptYSizeValue; 428 } 429 /** 430 * @return Returns the typeLineGap. 431 */ 432 public int getTypeLineGap() 433 { 434 return typeLineGap; 435 } 436 /** 437 * @param typeLineGapValue The typeLineGap to set. 438 */ 439 public void setTypeLineGap(int typeLineGapValue) 440 { 441 this.typeLineGap = typeLineGapValue; 442 } 443 /** 444 * @return Returns the typoAscender. 445 */ 446 public int getTypoAscender() 447 { 448 return typoAscender; 449 } 450 /** 451 * @param typoAscenderValue The typoAscender to set. 452 */ 453 public void setTypoAscender(int typoAscenderValue) 454 { 455 this.typoAscender = typoAscenderValue; 456 } 457 /** 458 * @return Returns the typoDescender. 459 */ 460 public int getTypoDescender() 461 { 462 return typoDescender; 463 } 464 /** 465 * @param typoDescenderValue The typoDescender to set. 466 */ 467 public void setTypoDescender(int typoDescenderValue) 468 { 469 this.typoDescender = typoDescenderValue; 470 } 471 /** 472 * @return Returns the unicodeRange1. 473 */ 474 public long getUnicodeRange1() 475 { 476 return unicodeRange1; 477 } 478 /** 479 * @param unicodeRange1Value The unicodeRange1 to set. 480 */ 481 public void setUnicodeRange1(long unicodeRange1Value) 482 { 483 this.unicodeRange1 = unicodeRange1Value; 484 } 485 /** 486 * @return Returns the unicodeRange2. 487 */ 488 public long getUnicodeRange2() 489 { 490 return unicodeRange2; 491 } 492 /** 493 * @param unicodeRange2Value The unicodeRange2 to set. 494 */ 495 public void setUnicodeRange2(long unicodeRange2Value) 496 { 497 this.unicodeRange2 = unicodeRange2Value; 498 } 499 /** 500 * @return Returns the unicodeRange3. 501 */ 502 public long getUnicodeRange3() 503 { 504 return unicodeRange3; 505 } 506 /** 507 * @param unicodeRange3Value The unicodeRange3 to set. 508 */ 509 public void setUnicodeRange3(long unicodeRange3Value) 510 { 511 this.unicodeRange3 = unicodeRange3Value; 512 } 513 /** 514 * @return Returns the unicodeRange4. 515 */ 516 public long getUnicodeRange4() 517 { 518 return unicodeRange4; 519 } 520 /** 521 * @param unicodeRange4Value The unicodeRange4 to set. 522 */ 523 public void setUnicodeRange4(long unicodeRange4Value) 524 { 525 this.unicodeRange4 = unicodeRange4Value; 526 } 527 /** 528 * @return Returns the version. 529 */ 530 public int getVersion() 531 { 532 return version; 533 } 534 /** 535 * @param versionValue The version to set. 536 */ 537 public void setVersion(int versionValue) 538 { 539 this.version = versionValue; 540 } 541 /** 542 * @return Returns the weightClass. 543 */ 544 public int getWeightClass() 545 { 546 return weightClass; 547 } 548 /** 549 * @param weightClassValue The weightClass to set. 550 */ 551 public void setWeightClass(int weightClassValue) 552 { 553 this.weightClass = weightClassValue; 554 } 555 /** 556 * @return Returns the widthClass. 557 */ 558 public int getWidthClass() 559 { 560 return widthClass; 561 } 562 /** 563 * @param widthClassValue The widthClass to set. 564 */ 565 public void setWidthClass(int widthClassValue) 566 { 567 this.widthClass = widthClassValue; 568 } 569 /** 570 * @return Returns the winAscent. 571 */ 572 public int getWinAscent() 573 { 574 return winAscent; 575 } 576 /** 577 * @param winAscentValue The winAscent to set. 578 */ 579 public void setWinAscent(int winAscentValue) 580 { 581 this.winAscent = winAscentValue; 582 } 583 /** 584 * @return Returns the winDescent. 585 */ 586 public int getWinDescent() 587 { 588 return winDescent; 589 } 590 /** 591 * @param winDescentValue The winDescent to set. 592 */ 593 public void setWinDescent(int winDescentValue) 594 { 595 this.winDescent = winDescentValue; 596 } 597 private int version; 598 private short averageCharWidth; 599 private int weightClass; 600 private int widthClass; 601 private short fsType; 602 private short subscriptXSize; 603 private short subscriptYSize; 604 private short subscriptXOffset; 605 private short subscriptYOffset; 606 private short superscriptXSize; 607 private short superscriptYSize; 608 private short superscriptXOffset; 609 private short superscriptYOffset; 610 private short strikeoutSize; 611 private short strikeoutPosition; 612 private short familyClass; 613 private byte[] panose = new byte[10]; 614 private long unicodeRange1; 615 private long unicodeRange2; 616 private long unicodeRange3; 617 private long unicodeRange4; 618 private String achVendId; 619 private int fsSelection; 620 private int firstCharIndex; 621 private int lastCharIndex; 622 private int typoAscender; 623 private int typoDescender; 624 private int typeLineGap; 625 private int winAscent; 626 private int winDescent; 627 private long codePageRange1 = -1; 628 private long codePageRange2 = -1; 629 630 /** 631 * A tag that identifies this table type. 632 */ 633 public static final String TAG = "OS/2"; 634 635 /** 636 * This will read the required data from the stream. 637 * 638 * @param ttf The font that is being read. 639 * @param data The stream to read the data from. 640 * @throws IOException If there is an error reading the data. 641 */ 642 public void initData( TrueTypeFont ttf, TTFDataStream data ) throws IOException 643 { 644 version = data.readUnsignedShort(); 645 averageCharWidth = data.readSignedShort(); 646 weightClass = data.readUnsignedShort(); 647 widthClass = data.readUnsignedShort(); 648 fsType = data.readSignedShort(); 649 subscriptXSize = data.readSignedShort(); 650 subscriptYSize = data.readSignedShort(); 651 subscriptXOffset = data.readSignedShort(); 652 subscriptYOffset = data.readSignedShort(); 653 superscriptXSize = data.readSignedShort(); 654 superscriptYSize = data.readSignedShort(); 655 superscriptXOffset = data.readSignedShort(); 656 superscriptYOffset = data.readSignedShort(); 657 strikeoutSize = data.readSignedShort(); 658 strikeoutPosition = data.readSignedShort(); 659 familyClass = data.readSignedShort(); 660 panose = data.read( 10 ); 661 unicodeRange1 = data.readUnsignedInt(); 662 unicodeRange2 = data.readUnsignedInt(); 663 unicodeRange3 = data.readUnsignedInt(); 664 unicodeRange4 = data.readUnsignedInt(); 665 achVendId = data.readString( 4 ); 666 fsSelection = data.readUnsignedShort(); 667 firstCharIndex = data.readUnsignedShort(); 668 lastCharIndex = data.readUnsignedShort(); 669 typoAscender = data.readSignedShort(); 670 typoDescender = data.readSignedShort(); 671 typeLineGap = data.readSignedShort(); 672 winAscent = data.readUnsignedShort(); 673 winDescent = data.readUnsignedShort(); 674 if( version >= 1 ) 675 { 676 codePageRange1 = data.readUnsignedInt(); 677 codePageRange2 = data.readUnsignedInt(); 678 } 679 } 680 }