afmdiff.awk 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. ###=====================================================================
  2. ### Read two Adobe Font Metric files, and compute tables of the
  3. ### differences in character repertoire, declared widths (WX), and
  4. ### bounding boxes.
  5. ###
  6. ### Usage:
  7. ### awk -f afmdiff.awk file1.afm file2.afm
  8. ###
  9. ### Author:
  10. ### Nelson H. F. Beebe
  11. ### Center for Scientific Computing
  12. ### University of Utah
  13. ### Department of Mathematics, 322 INSCC
  14. ### 155 S 1400 E RM 233
  15. ### Salt Lake City, UT 84112-0090
  16. ### USA
  17. ### Email: beebe@math.utah.edu, beebe@acm.org, beebe@computer.org,
  18. ### beebe@ieee.org (Internet)
  19. ### WWW URL: http://www.math.utah.edu/~beebe
  20. ### Telephone: +1 801 581 5254
  21. ### FAX: +1 801 585 1640, +1 801 581 4148
  22. ###
  23. ########################################################################
  24. ########################################################################
  25. ########################################################################
  26. ### ###
  27. ### awkdiff.awk: compare two Adobe Font Metric files ###
  28. ### ###
  29. ### Copyright (C) 2000 Nelson H. F. Beebe ###
  30. ### ###
  31. ### This program is covered by the GNU General Public License (GPL), ###
  32. ### version 2 or later, available as the file COPYING in the program ###
  33. ### source distribution, and on the Internet at ###
  34. ### ###
  35. ### ftp://ftp.gnu.org/gnu/GPL ###
  36. ### ###
  37. ### http://www.gnu.org/copyleft/gpl.html ###
  38. ### ###
  39. ### This program is free software; you can redistribute it and/or ###
  40. ### modify it under the terms of the GNU General Public License as ###
  41. ### published by the Free Software Foundation; either version 2 of ###
  42. ### the License, or (at your option) any later version. ###
  43. ### ###
  44. ### This program is distributed in the hope that it will be useful, ###
  45. ### but WITHOUT ANY WARRANTY; without even the implied warranty of ###
  46. ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ###
  47. ### GNU General Public License for more details. ###
  48. ### ###
  49. ### You should have received a copy of the GNU General Public ###
  50. ### License along with this program; if not, write to the Free ###
  51. ### Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, ###
  52. ### MA 02111-1307 USA ###
  53. ### ###
  54. ### This program may also be distributed as part of AFPL ###
  55. ### Ghostscript, under the terms of the Aladdin Free Public License ###
  56. ### (the "License"). ###
  57. ### ###
  58. ### Every copy of AFPL Ghostscript must include a copy of the ###
  59. ### License, normally in a plain ASCII text file named PUBLIC. The ###
  60. ### License grants you the right to copy, modify and redistribute ###
  61. ### AFPL Ghostscript, but only under certain conditions ###
  62. ### described in the License. Among other things, the License ###
  63. ### requires that the copyright notice and this notice be preserved ###
  64. ### on all copies. ###
  65. ### ###
  66. ########################################################################
  67. ########################################################################
  68. ########################################################################
  69. #
  70. # [29-Apr-2000]
  71. #=======================================================================
  72. /^FontName/ { FontName[++NFontName] = $2 }
  73. /^C / {
  74. if (NFontName == 1)
  75. CharName1[$8]++
  76. if (NFontName == 2)
  77. CharName2[$8]++
  78. }
  79. /^C / {
  80. name = $8
  81. if (name in WX)
  82. {
  83. if (WX[name] != $5)
  84. WXDIFF[name] = WX[name] - $5
  85. }
  86. else
  87. WX[name] = $5
  88. }
  89. /^C / {
  90. name = $8
  91. bx = $13 - $11
  92. if (name in BX)
  93. {
  94. if (BX[name] != bx)
  95. BXDIFF[name] = BX[name] - bx
  96. }
  97. else
  98. BX[name] = bx
  99. }
  100. /^C / {
  101. name = $8
  102. by = $14 - $12
  103. if (name in BY)
  104. {
  105. if (BY[name] != by)
  106. BYDIFF[name] = BY[name] - by
  107. }
  108. else
  109. BY[name] = by
  110. }
  111. END {
  112. Sortpipe = "sort -f | pr -c3 -w80 -l1 -t"
  113. print "Comparison of AFM metrics in files:", ARGV[1], ARGV[2]
  114. print "Font names:", FontName[1], FontName[2]
  115. show_name_diffs(FontName[2],CharName2, FontName[1],CharName1)
  116. show_name_diffs(FontName[1],CharName1, FontName[2],CharName2)
  117. show_num_diffs("WX width differences", WXDIFF)
  118. show_num_diffs("Bounding box width differences", BXDIFF)
  119. show_num_diffs("Bounding box height differences",BYDIFF)
  120. }
  121. function show_name_diffs(font1,array1,font2,array2, name)
  122. {
  123. print "\nChars from", font2, "missing from", font1 ":"
  124. for (name in array2)
  125. {
  126. if (!(name in array1))
  127. printf("%s\n", name) | Sortpipe
  128. }
  129. close(Sortpipe)
  130. }
  131. function show_num_diffs(title,array, name)
  132. {
  133. printf("\n%s:\n", title)
  134. for (name in array)
  135. printf("%-15s\t%4d\n", name, array[name]) | Sortpipe
  136. close(Sortpipe)
  137. }