OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <fcntl.h> | 5 #include <fcntl.h> |
6 #include <ft2build.h> | 6 #include <ft2build.h> |
7 #include FT_FREETYPE_H | 7 #include FT_FREETYPE_H |
8 #include FT_OUTLINE_H | 8 #include FT_OUTLINE_H |
9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
11 #include <unistd.h> | 11 #include <unistd.h> |
12 | 12 |
13 #include <cstdio> | 13 #include <cstdio> |
14 #include <cstdlib> | 14 #include <cstdlib> |
15 #include <cstring> | 15 #include <cstring> |
16 | 16 |
17 #include "opentype-sanitiser.h" | 17 #include "opentype-sanitiser.h" |
18 #include "ots-memory-stream.h" | 18 #include "ots-memory-stream.h" |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 void DumpBitmap(const FT_Bitmap *bitmap) { | 22 void DumpBitmap(const FT_Bitmap *bitmap) { |
23 for (int i = 0; i < bitmap->rows * bitmap->width; ++i) { | 23 for (unsigned int i = 0; i < bitmap->rows * bitmap->width; ++i) { |
24 if (bitmap->buffer[i] > 192) { | 24 if (bitmap->buffer[i] > 192) { |
25 std::fprintf(stderr, "#"); | 25 std::fprintf(stderr, "#"); |
26 } else if (bitmap->buffer[i] > 128) { | 26 } else if (bitmap->buffer[i] > 128) { |
27 std::fprintf(stderr, "*"); | 27 std::fprintf(stderr, "*"); |
28 } else if (bitmap->buffer[i] > 64) { | 28 } else if (bitmap->buffer[i] > 64) { |
29 std::fprintf(stderr, "+"); | 29 std::fprintf(stderr, "+"); |
30 } else if (bitmap->buffer[i] > 32) { | 30 } else if (bitmap->buffer[i] > 32) { |
31 std::fprintf(stderr, "."); | 31 std::fprintf(stderr, "."); |
32 } else { | 32 } else { |
33 std::fprintf(stderr, " "); | 33 std::fprintf(stderr, " "); |
34 } | 34 } |
35 | 35 |
36 if ((i + 1) % bitmap->width == 0) { | 36 if ((i + 1) % bitmap->width == 0) { |
37 std::fprintf(stderr, "\n"); | 37 std::fprintf(stderr, "\n"); |
38 } | 38 } |
39 } | 39 } |
40 } | 40 } |
41 | 41 |
42 int CompareBitmaps(const FT_Bitmap *orig, const FT_Bitmap *trans) { | 42 int CompareBitmaps(const FT_Bitmap *orig, const FT_Bitmap *trans) { |
43 int ret = 0; | 43 int ret = 0; |
44 | 44 |
45 if (orig->width == trans->width && | 45 if (orig->width == trans->width && |
46 orig->rows == trans->rows) { | 46 orig->rows == trans->rows) { |
47 for (int i = 0; i < orig->rows * orig->width; ++i) { | 47 for (unsigned int i = 0; i < orig->rows * orig->width; ++i) { |
48 if (orig->buffer[i] != trans->buffer[i]) { | 48 if (orig->buffer[i] != trans->buffer[i]) { |
49 std::fprintf(stderr, "bitmap data doesn't match!\n"); | 49 std::fprintf(stderr, "bitmap data doesn't match!\n"); |
50 ret = 1; | 50 ret = 1; |
51 break; | 51 break; |
52 } | 52 } |
53 } | 53 } |
54 } else { | 54 } else { |
55 std::fprintf(stderr, "bitmap metrics doesn't match! (%d, %d), (%d, %d)\n", | 55 std::fprintf(stderr, "bitmap metrics doesn't match! (%d, %d), (%d, %d)\n", |
56 orig->width, orig->rows, trans->width, trans->rows); | 56 orig->width, orig->rows, trans->width, trans->rows); |
57 ret = 1; | 57 ret = 1; |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 std::fprintf(stderr, "Failed to sanitise file! %s\n", argv[1]); | 272 std::fprintf(stderr, "Failed to sanitise file! %s\n", argv[1]); |
273 return 1; | 273 return 1; |
274 } | 274 } |
275 const size_t trans_len = output.Tell(); | 275 const size_t trans_len = output.Tell(); |
276 | 276 |
277 // perform side-by-side tests. | 277 // perform side-by-side tests. |
278 return SideBySide(library, argv[1], | 278 return SideBySide(library, argv[1], |
279 orig_font, orig_len, | 279 orig_font, orig_len, |
280 trans_font, trans_len); | 280 trans_font, trans_len); |
281 } | 281 } |
OLD | NEW |