星火微课系统客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

afmdiff.awk 5.6KB

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