1 StarView Metafile 2 3 Specification 4 5 Inge Wallin 6 Pierre Ducroquet 7 8 91. Introduction 10=============== 11 12This file describes the format of a StarView Metafile, SVM, the vector 13file format that is used by Star Office, OpenOffice.org, and 14LibreOffice to create object replacement images. 15 16As far as we know, there is no formal specification of this format. This 17documentation has therefore been created by reading the source code of 18LibreOffice. 19 20The structure of this document is modeled after the documentations of Windows 21MetaFile ([MS-WMF].pdf) and the Extended MetaFile ([MS-EMF].pdf) from 22Microsoft. 23 24 251.1 Glossary 26------------ 27FIXME 28 29 301.2 Structure Overview 31---------------------- 32 33An SVM file always starts with a signature of 6 bytes that identifies 34the file as an SVM. This signature is always the string "VCLMTF" 35(excluding the quotes). 36 37Second, there is a header object describing the rest of the file. 38 39Third, the header is followed by a number of actions as specified in 40the header. Each action or object, including the header, starts with 41a VersionCompat object that specifies the version and size of the 42action or object in question. The size in the VersionCompat object is 43*excluding* the VersionCompat itself. 44 45 462. Structures 47============= 48 49This section specifies the structures used in a StarView 50Metafile. This includes: 51 52 * enumerations of SVM constants: enums and flags 53 54 * definitions of SVM objects, i.e. primitive data types and 55 composite structs and objects 56 57 * specifications of SVM actions. 58 59 602.1 SVM Constants 61----------------- 62 63Constants come in two different forms: enumerations and flags. 64 65 662.1.1 SVM Enumerations 67- - - - - - - - - - - - 68 69The following enumerations should be used in programs that handle SVM 70files. 71 72 732.1.1.1 ActionType Enumeration 74 75The ActionType Enumeration defines the type of actions that can be 76used in an SVM file. 77 78enum ActionType { 79 META_NULL_ACTION = 0, 80 META_PIXEL_ACTION = 100, 81 META_POINT_ACTION = 101, 82 META_LINE_ACTION = 102, 83 META_RECT_ACTION = 103, 84 META_ROUNDRECT_ACTION = 104, 85 META_ELLIPSE_ACTION = 105 86 META_ARC_ACTION = 106, 87 META_PIE_ACTION = 107, 88 META_CHORD_ACTION = 108, 89 META_POLYLINE_ACTION = 109, 90 META_POLYGON_ACTION = 110, 91 META_POLYPOLYGON_ACTION = 111, 92 META_TEXT_ACTION = 112, 93 META_TEXTARRAY_ACTION = 113, 94 META_STRETCHTEXT_ACTION = 114, 95 META_TEXTRECT_ACTION = 115, 96 META_BMP_ACTION = 116, 97 META_BMPSCALE_ACTION = 117, 98 META_BMPSCALEPART_ACTION = 118, 99 META_BMPEX_ACTION = 119, 100 META_BMPEXSCALE_ACTION = 120, 101 META_BMPEXSCALEPART_ACTION = 121, 102 META_MASK_ACTION = 122, 103 META_MASKSCALE_ACTION = 123, 104 META_MASKSCALEPART_ACTION = 124, 105 META_GRADIENT_ACTION = 125, 106 META_HATCH_ACTION = 126, 107 META_WALLPAPER_ACTION = 127, 108 META_CLIPREGION_ACTION = 128, 109 META_ISECTRECTCLIPREGION_ACTION = 129, 110 META_ISECTREGIONCLIPREGION_ACTION = 130, 111 META_MOVECLIPREGION_ACTION = 131, 112 META_LINECOLOR_ACTION = 132, 113 META_FILLCOLOR_ACTION = 133, 114 META_TEXTCOLOR_ACTION = 134, 115 META_TEXTFILLCOLOR_ACTION = 135, 116 META_TEXTALIGN_ACTION = 136, 117 META_MAPMODE_ACTION = 137, 118 META_FONT_ACTION = 138, 119 META_PUSH_ACTION = 139, 120 META_POP_ACTION = 140, 121 META_RASTEROP_ACTION = 141, 122 META_TRANSPARENT_ACTION = 142, 123 META_EPS_ACTION = 143, 124 META_REFPOINT_ACTION = 144, 125 META_TEXTLINECOLOR_ACTION = 145, 126 META_TEXTLINE_ACTION = 146, 127 META_FLOATTRANSPARENT_ACTION = 147, 128 META_GRADIENTEX_ACTION = 148, 129 META_LAYOUTMODE_ACTION = 149, 130 META_TEXTLANGUAGE_ACTION = 150, 131 META_OVERLINECOLOR_ACTION = 151, 132 META_COMMENT_ACTION = 512 133}; 134 135 1362.1.1.2 Mtf Enumeration 137 138The Mtf Enumeration defines ... FIXME 139 140enum MtfType { 141 MTF_CONVERSION_NONE = 0, 142 MTF_CONVERSION_1BIT_THRESHOLD = 1, 143 MTF_CONVERSION_8BIT_GREYS = 2 144}; 145 146 1472.1.1.3 LineStyle Enumeration 148 149enum LineStyle 150{ 151 LINE_NONE = 0, 152 LINE_SOLID = 1, 153 LINE_DASH = 2 154}; 155 156 1572.1.1.4 LayoutMode Enumeration 158 159enum LayoutMode 160{ 161 TEXT_LAYOUT_DEFAULT = 0x0000, 162 TEXT_LAYOUT_BIDI_LTR = 0x0000, 163 TEXT_LAYOUT_BIDI_RTL = 0x0001, 164 TEXT_LAYOUT_BIDI_STRONG = 0x0002, 165 TEXT_LAYOUT_TEXTORIGIN_LEFT = 0x0004, 166 TEXT_LAYOUT_TEXTORIGIN_RIGHT = 0x0008, 167 TEXT_LAYOUT_COMPLEX_DISABLED = 0x0100, 168 TEXT_LAYOUT_ENABLE_LIGATURES = 0x0200, 169 TEXT_LAYOUT_SUBSTITUTE_DIGITS = 0x0400 170}; 171 172 1732.1.1.5 ... Enumeration 174FIXME 175 176 1772.1.2 SVM Flags 178- - - - - - - - 179 180A variable can only containing one value from an SVM enumeration at 181the same time. In contrast, a variable containing SVN flags can 182combine as many values from the respective definition of flags as the 183enumeration of the flag itself. 184 185 1862.1.2.1 Mirror Flags 187 188MTF_MIRROR_NONE 0x00000000 189MTF_MIRROR_HORZ 0x00000001 190MTF_MIRROR_VERT 0x00000002 191 192FIXME: Check the details here. 193MTF_MIRROR_NONE The picture is not mirrored in any direction. 194 195MTF_MIRROR_HORZ The picture should be drawn mirrored horizontally, 196 i.e. mirrored in the center line of the picture 197 parallel to the Y axis. 198 199MTF_MIRROR_VERT The picture should be drawn mirrored vertically, 200 i.e. mirrored in the center line of the picture 201 parallel to the X axis. 202 203In all of the cases above, the space occupied by the picture is the 204same. 205 206 2072.2 SVM Objects 208--------------- 209 210This section specifies the objects used in SVM files. 211 212 2132.2.1 Primitive Data Types 214- - - - - - - - - - - - - - 215 216The following primitive data types are used in the objects or actions. 217 218uint8 an unsigned 8 bit integer, taking up 1 byte in the file. 219int8 a signed 8 bit integer, taking up 1 byte in the file. 220uint16 an unsigned 16 bit integer, taking up 2 bytes in the file. 221int16 a signed 16 bit integer, taking up 2 bytes in the file. 222uint32 an unsigned 32 bit integer, taking up 4 bytes in the file. 223int32 a signed 32 bit integer, taking up 4 bytes in the file. 224bool an unsigned 8 bit value, taking up 1 byte in the file 225 226Floating point values are not used in SVM. 227 228 2292.2.1 Basic Objects 230- - - - - - - - - - 231 232These object types are mostly used as primitives in the larger and 233more complex object types and actions. 234 235 2362.2.1.1 VersionCompat Object 237 238The VersionCompat object is always the first object of any bigger 239object and any action. This object describes which version the object 240or action has. 241 242struct VersionCompat { 243 uint16 version; 244 uint32 length; 245} 246 247version defines the version of the object. Depending on the 248 version, the object will have a different number of 249 components, thus changing the parser behaviour. 250 251length defines the length of the object, excluding the 252 VersionCompat object. 253 254 2552.2.1.2 Point 256 257struct Point { 258 uint32 x; 259 uint32 y; 260} 261 262 2632.2.1.3 Polygon 264 265struct Polygon { 266 uint16 nPoints; 267 Point points[nPoints]; 268} 269 270 2712.2.1.4 PolyPolygon 272 273struct PolyPolygon { 274 uint16 nPolygons; 275 Polygon polygons[nPolygons]; 276} 277 278 2792.2.1.5 String 280 281struct String { 282 uint16 size; 283 char data[size]; 284} 285 286A string object is built in a Pascal style, not a C style. There is 287no trailing \0 at the end of the string. 288 289 2902.2.1.6 Fraction 291 292struct Fraction { 293 uint32 numerator; 294 unit32 denominator; 295} 296 297The value of a Fraction is numerator/denominator. 298 299 3002.2.2 Header Object 301- - - - - - - - - - 302 303The header object is a special object in an SVM. It is always the 304first object in the file. There is only one header object. 305 306VersionCompat versionCompat 307uint32 compressionMode 308MapMode mapMode 309uint32 width 310uint32 height 311uint32 actionCount 312 313versionCompat Version and size of the header record, excluding the 314 VersionCompat object. 315 316compressionMode ... FIXME 317 318mapMode Default MapMode for the file. FIXME: Check if true 319 320width Width of the picture in logical coordinates. 321 322height Height of the picture in logical coordinates. 323 324actionCount Number of Actions in the file. 325 326 3272.2.3 Graphics Objects 328- - - - - - - - - - - - 329 330The SVM Graphics Objects specify parameters for graphics output. A 331particular graphics object becomes part of the drawing context when it 332is selected by an appropriate object record, and it is reused in 333subsequent graphics operations until a different object is selected. 334 335 3362.2.3.1 MapMode 337 338This object describes some properties of the current drawing. 339 340VersionCompat version 341uint16 unit 342Point origin 343Fraction scaleX 344Fraction scaleY 345bool isSimple 346 347....FIXME: how do they alter the rendering context ? 348.... Can the scale, the origin change ? 349.... Find the values for the unit... 350 351 3522.2.3.2 Font 353 354This object describes the properties of a font face to be used when rendering text. 355 356VersionCompat version 357String family 358String style 359uint32 fontWidth 360uint32 fontHeight 361uint16 charset 362uint16 family 363uint16 pitch 364uint16 weight 365uint16 underline 366uint16 strikeout 367uint16 italic 368uint16 language 369uint16 width 370uint16 orientation 371bool wordline 372bool outline 373bool shadow 374int8 kerning 375 If version is greater than 1: 376int8 relief 377uint16 language 378bool vertical 379uint16 emphasis 380 If version is greater than 2: 381uint16 overline 382 383version Version and size of the font record, excluding the 384 VersionCompat object. 385 386FIXME: Describe the following parts in detail 387family 388style 389fontWidth 390fontHeight 391charset 392family 393pitch 394weight 395underline 396strikeout 397italic 398language 399width 400orientation 401wordline 402outline 403shadow 404kerning 405 If version is greater than 1: 406relief 407language 408vertical 409emphasis 410 If version is greater than 2: 411overline 412 413 414 4152.2.4 Structure Objects 416- - - - - - - - - - - - 417 418The SVM Structure Objects specify data structures that are embedded in 419SVM objects and actions. Structure objects, unlike graphics objects, 420are not explicitly created or deleted; they are components of more 421complex structures. 422 423 4242.2.4.1 Color 425 426FIXME 427 428 4292.2.4.2 PenInformations 430 431This object describes the pen properties for drawing lines. Its 432contents depends on its version. 433 434 For all values of version: 435VersionCompat version 436uint16 lineStyle 437uint32 lineWidth 438 If version is greater than 1: 439uint16 dashCount 440uint32 dashLength 441uint16 dotCount 442uint32 dotLength 443uint32 distance 444 If version is greater than 2: 445uint16 lineJoin 446 447lineStyle describes the line style of the pen. It can take any 448 value of the LineStyle enumeration. 449 450lineWidth width of the pen in <unit> (FIXME) 451 452....FIXME: how to interpret the next fields values ? 453 454 4552.3 SVM Actions 456--------------- 457 458The action type is specified using a uint16 at the beginning of each 459action following the file header. Every action except the special 460META_NULL_ACTION begins with a VersionCompat object. 461 462 4632.3.1 Control Action Types 464- - - - - - - - - - - - - - 465 4662.3.1.1 META_NULL_ACTION (0) 467 468This action should never occur, ever. 469It contains a uint16 that is never used. 470 471 4722.3.1.2 META_COMMENT_ACTION (512) 473 474A comment action has no effect on the rendering. 475 476string comment 477uint32 value 478string comment2 479 480 481comment The comment text 482 483value ... FIXME 484 485comment2 ... FIXME 486 487 4882.3.2 State Action Types 489- - - - - - - - - - - - - 490 491These actions change the state of the drawing context. 492 493 4942.3.2.1 META_LINECOLOR_ACTION (132) 495 496A line color sets the pen color in the drawing context. 497 498uint32 colorData 499bool doSet 500 501colorData The color of the pen, in RGB format 502 (... QColor::fromRgb format) 503 504doSet Should the color be applied (true), or should the pen 505 be hidden (false) 506 507 5082.3.2.2 META_FILLCOLOR_ACTION (133) 509 510A fill color sets the brush color in the current context. 511 512It contains the following parts 513uint32 colorData 514bool isSet 515 516colorData The color of the brush, in RGB format 517 (... QColor::fromRgb format) 518 519isSet Specifies whether the color should be be applied 520 (true), or if the brush should be hidden (false) 521 522 5232.3.2.3 META_MAPMODE_ACTION (137) 524 525This action loads a new MapMode object into the drawing context. 526 527MapMode mapMode 528 529 5302.3.2.4 META_FONT_ACTION (138) 531 532This action sets the current font in the graphics context. 533 534Font font 535 536font The new font that will be used when writing text. 537 538 539 5402.3.2.5 META_LAYOUTMODE_ACTION (149) 541 542This action sets the current layout mode in the graphics context. 543 544uint32 layoutMode 545 546layoutMode This defines the text layout mode. It should contain 547 one of the values of the LayoutMode enumeration. 548 549 5502.3.2.6 META_TEXTLANGUAGE_ACTION (150) 551 552This action sets the current text language in the graphics context. 553 554uint16 languageType 555 556languageType It is a decimal code that specifies the language. 557 It is described in i18npool/inc/i18npool/lang.h 558 FIXME: Add these language codes to the enums in 2.1.1 559 560 5612.3.3 Drawing Action Types 562- - - - - - - - - - - - - - 563 564These actions all cause some form of output to the picture. The 565operations described by these actions are influenced by the current 566drawing context. 567 568 5692.3.3.1 META_POLYLINE_ACTION (109) 570 571A polyline action draws a polygon without filling it. 572 573It contains the following parts 574Polygon polygon 575 If the version of the action is greater than 1: 576PenInformations penInfos 577 If the version of the action is greater than 2: 578bool polygonFlags 579 If polygonFlags is true: 580VersionCompat flagsVersionCompat 581Polygon polygon (replaces the previous polygon) 582bool polygonFlagsEnabled 583 If polygonFlagsEnabled 584....... FIXME! 585 586polygon The polygon to draw 587 588penInfos The pen style to apply 589 590polygonFlags Indicate the presence of extra polygon informations 591....... FIXME: next part is complicated... 592 593 5942.3.3.2 META_POLYGON_ACTION (110) 595 596A polygon action draws a polygon and filling it. 597 598// FIXME: Check if the following is true. Right now it is just copied 599// from META_POLYLINE_ACTION 600Polygon polygon 601 If the version of the action is greater than 1: 602PenInformations penInfos 603 If the version of the action is greater than 2: 604bool polygonFlags 605 If polygonFlags is true: 606VersionCompat flagsVersionCompat 607Polygon polygon (replaces the previous polygon) 608bool polygonFlagsEnabled 609 If polygonFlagsEnabled 610....... FIXME! 611 612polygon The polygon to draw 613 614penInfos The pen style to apply 615 616polygonFlags Indicate the presence of extra polygon informations 617....... FIXME: next part is complicated... 618 619 6202.3.3.3 META_POLYPOLYGON_ACTION (111) 621 622A polypolygon action draws a group of polygons. 623 624It contains the following parts 625PolyPolygon polygons 626 If the version of the action is greater than 1: 627uint16 numberOfComplexPolygons 628For each complexPolygon : 629uint16 complexPolygonIndex 630Polygon complexPolygon 631 632The complexPolygonIndex is used to replace a polygon from the polygons list. 633 634 6352.3.3.4 META_TEXT_ACTION 636 637... 638 639 6402.3.3.5 META_TEXTARRAY_ACTION 641 642The textarray action draws a complex text. 643 644It contains the following parts 645 646Point startPoint 647String string 648uint16 startIndex 649uint16 len 650uint32 dxArrayLen 651int32 dxArray[] 652 If version is greater than 1: 653uint16 len2 654unicodechar chars[len2] 655 656 657startPoint The point where the string is drawn 658 659string the text string 660 661startIndex The index of the first character of the string that 662 should be drawn. 663 664len The number of characters that should be drawn, 665 starting with the character at 'startIndex'. 666 667dxArrayLen The number of character offsets in dxArray 668 669dxArray An array of character offsets for the characters in 670 the string. The number of offsets is stored in 671 dxArrayLen. FIXME: What unit is this in? 672 673 6742.3.4 Unsorted Action Types 675- - - - - - - - - - - - - - 676 677These action types have so far not being sorted into any other type. 678 679 META_PIXEL_ACTION 680 META_POINT_ACTION 681 META_LINE_ACTION 682 META_RECT_ACTION 683 META_ROUNDRECT_ACTION 684 META_ELLIPSE_ACTION 685 META_ARC_ACTION 686 META_PIE_ACTION 687 META_CHORD_ACTION 688 META_POLYGON_ACTION 689 META_STRETCHTEXT_ACTION 690 META_TEXTRECT_ACTION 691 META_BMP_ACTION 692 META_BMPSCALE_ACTION 693 META_BMPSCALEPART_ACTION 694 META_BMPEX_ACTION 695 META_BMPEXSCALE_ACTION 696 META_BMPEXSCALEPART_ACTION 697 META_MASK_ACTION 698 META_MASKSCALE_ACTION 699 META_MASKSCALEPART_ACTION 700 META_GRADIENT_ACTION 701 META_HATCH_ACTION 702 META_WALLPAPER_ACTION 703 META_CLIPREGION_ACTION 704 META_ISECTRECTCLIPREGION_ACTION 705 META_ISECTREGIONCLIPREGION_ACTION 706 META_MOVECLIPREGION_ACTION 707 META_TEXTCOLOR_ACTION 708 META_TEXTFILLCOLOR_ACTION 709 META_TEXTALIGN_ACTION 710 META_FONT_ACTION 711 META_PUSH_ACTION 712 META_POP_ACTION 713 META_RASTEROP_ACTION 714 META_TRANSPARENT_ACTION 715 META_EPS_ACTION 716 META_REFPOINT_ACTION 717 META_TEXTLINECOLOR_ACTION 718 META_TEXTLINE_ACTION 719 META_FLOATTRANSPARENT_ACTION 720 META_GRADIENTEX_ACTION 721 META_LAYOUTMODE_ACTION 722 META_OVERLINECOLOR_ACTION 723 724 725Appendix A: Sources 726 727This documentation has been created by reading the source code of 728LibreOffice. The following files were used: 729 730tools/inc/tools/fontenum.hxx Enums for fonts 731 FontFamily, FontPitch, TextAlign, 732 FontWeight, FontWidth, FontItalic, 733 FontUnderLine, FontStrikeout, 734 FontEmphasisMark (#defines instead of enum), 735 FontType, FontEmbeddedBitmap, FontAntiAlias 736 737vcl/inc/vcl/gdimtf.hxx The main GDI file object 738vcl/source/gdi/gdimtf.cxx 739vcl/inc/vcl/metaact.hxx Metafile actions 740vcl/source/gdi/metaact.cxx 741vcl/inc/vcl/outdev.hxx Enums, defines and flags for outdevice: 742 Push, DrawText, Drawimage, Grid, ComplexTextLayout, 743 DrawModes, AntiAlias, AddFontSubstitute 744