xfa_tohtml_spec.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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="FooBar" 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. <breakBefore targetType="pageArea" startNew="1"/>
  53. </subform>
  54. </subform>
  55. </template>
  56. <xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
  57. <xfa:data>
  58. </xfa:data>
  59. </xfa:datasets>
  60. </xdp:xdp>
  61. `;
  62. const factory = new _factory.XFAFactory({
  63. "xdp:xdp": xml
  64. });
  65. expect(factory.numberPages).toEqual(2);
  66. const page1 = factory.getPage(0);
  67. expect(page1.attributes.style).toEqual({
  68. height: "789px",
  69. width: "456px"
  70. });
  71. expect(page1.children.length).toEqual(2);
  72. const container = page1.children[0];
  73. expect(container.attributes.class).toEqual("xfaContentarea");
  74. expect(container.attributes.style).toEqual({
  75. height: "789px",
  76. width: "456px",
  77. left: "123px",
  78. top: "0px",
  79. position: "absolute"
  80. });
  81. const wrapper = page1.children[1];
  82. const draw = wrapper.children[0];
  83. expect(wrapper.attributes.class).toEqual("xfaWrapper");
  84. expect(wrapper.attributes.style).toEqual({
  85. left: "2px",
  86. position: "absolute",
  87. top: "1px"
  88. });
  89. expect(draw.attributes.class).toEqual("xfaDraw xfaFont");
  90. expect(draw.attributes.style).toEqual({
  91. color: "#0c1722",
  92. fontFamily: "FooBar",
  93. fontSize: "6.93px",
  94. height: "22px",
  95. padding: "1px 4px 2px 3px",
  96. transform: "rotate(-90deg)",
  97. transformOrigin: "top left",
  98. verticalAlign: "2px",
  99. width: "11px"
  100. });
  101. expect(draw.attributes.style).toEqual(factory.getPage(1).children[1].children[0].attributes.style);
  102. });
  103. });
  104. });