xfa_tohtml_spec.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2021 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * Javascript code in this page
  21. */
  22. "use strict";
  23. var _factory = require("../../core/xfa/factory.js");
  24. describe("XFAFactory", function () {
  25. describe("toHTML", function () {
  26. it("should convert some basic properties to CSS", function () {
  27. const xml = `
  28. <?xml version="1.0"?>
  29. <xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/">
  30. <template xmlns="http://www.xfa.org/schema/xfa-template/3.3">
  31. <subform name="root" mergeMode="matchTemplate">
  32. <pageSet>
  33. <pageArea>
  34. <contentArea x="123pt" w="456pt" h="789pt"/>
  35. <medium stock="default" short="456pt" long="789pt"/>
  36. <draw y="1pt" w="11pt" h="22pt" rotate="90" x="2pt">
  37. <font size="7pt" typeface="Arial" baselineShift="2pt">
  38. <fill>
  39. <color value="12,23,34"/>
  40. <solid/>
  41. </fill>
  42. </font>
  43. <value/>
  44. <margin topInset="1pt" bottomInset="2pt" leftInset="3pt" rightInset="4pt"/>
  45. <para spaceAbove="1pt" spaceBelow="2pt" textIndent="3pt" marginLeft="4pt" marginRight="5pt"/>
  46. </draw>
  47. </pageArea>
  48. </pageSet>
  49. <subform name="first">
  50. </subform>
  51. <subform name="second">
  52. </subform>
  53. </subform>
  54. </template>
  55. <xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
  56. <xfa:data>
  57. </xfa:data>
  58. </xfa:datasets>
  59. </xdp:xdp>
  60. `;
  61. const factory = new _factory.XFAFactory({
  62. "xdp:xdp": xml
  63. });
  64. expect(factory.numberPages).toEqual(2);
  65. const page1 = factory.getPage(0);
  66. expect(page1.attributes.style).toEqual({
  67. height: "789px",
  68. width: "456px"
  69. });
  70. expect(page1.children.length).toEqual(2);
  71. const container = page1.children[0];
  72. expect(container.attributes.class).toEqual("xfaContentarea");
  73. expect(container.attributes.style).toEqual({
  74. height: "789px",
  75. width: "456px",
  76. left: "123px",
  77. top: "0px",
  78. position: "absolute"
  79. });
  80. const draw = page1.children[1];
  81. expect(draw.attributes.class).toEqual("xfaDraw xfaFont");
  82. expect(draw.attributes.style).toEqual({
  83. color: "#0c1722",
  84. fontFamily: "Arial",
  85. fontSize: "7px",
  86. height: "22px",
  87. left: "2px",
  88. position: "absolute",
  89. top: "1px",
  90. transform: "rotate(-90deg)",
  91. transformOrigin: "top left",
  92. verticalAlign: "2px",
  93. width: "11px"
  94. });
  95. expect(draw.attributes.style).toEqual(factory.getPage(1).children[1].attributes.style);
  96. });
  97. });
  98. });