default_appearance_spec.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* Copyright 2020 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. import {
  16. createDefaultAppearance,
  17. parseDefaultAppearance,
  18. } from "../../src/core/default_appearance.js";
  19. describe("Default appearance", function () {
  20. describe("parseDefaultAppearance and createDefaultAppearance", function () {
  21. it("should parse and create default appearance", function () {
  22. const da = "/F1 12 Tf 0.1 0.2 0.3 rg";
  23. const result = {
  24. fontSize: 12,
  25. fontName: "F1",
  26. fontColor: new Uint8ClampedArray([26, 51, 76]),
  27. };
  28. expect(parseDefaultAppearance(da)).toEqual(result);
  29. expect(createDefaultAppearance(result)).toEqual(da);
  30. expect(
  31. parseDefaultAppearance(
  32. "0.1 0.2 0.3 rg /F1 12 Tf 0.3 0.2 0.1 rg /F2 13 Tf"
  33. )
  34. ).toEqual({
  35. fontSize: 13,
  36. fontName: "F2",
  37. fontColor: new Uint8ClampedArray([76, 51, 26]),
  38. });
  39. });
  40. it("should parse default appearance with save/restore", function () {
  41. const da = "q Q 0.1 0.2 0.3 rg /F1 12 Tf q 0.3 0.2 0.1 rg /F2 13 Tf Q";
  42. expect(parseDefaultAppearance(da)).toEqual({
  43. fontSize: 12,
  44. fontName: "F1",
  45. fontColor: new Uint8ClampedArray([26, 51, 76]),
  46. });
  47. });
  48. });
  49. });