aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/pdf
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-04-18 19:29:07 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-04-18 19:29:07 +0000
commitaec406650cbfa4ef65d83db5ff4f82572e8e098f (patch)
treedfc4bd1845a09779496bef36e89f6aefd8c91361 /src/pdf
parent770963f23f4fc313db0fa3bac18b1b8aafb55f17 (diff)
fix int/size_t warnings
patch from issue 239933002 BUG=skia: R=bungeman@google.com Review URL: https://codereview.chromium.org/242113010 git-svn-id: http://skia.googlecode.com/svn/trunk@14259 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/pdf')
-rw-r--r--src/pdf/SkPDFDevice.cpp21
-rw-r--r--src/pdf/SkPDFFont.cpp27
-rw-r--r--src/pdf/SkPDFFont.h2
-rw-r--r--src/pdf/SkPDFTypes.h8
4 files changed, 32 insertions, 26 deletions
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp
index 246f30ded1..52fc2d28a1 100644
--- a/src/pdf/SkPDFDevice.cpp
+++ b/src/pdf/SkPDFDevice.cpp
@@ -131,12 +131,12 @@ static int max_glyphid_for_typeface(SkTypeface* typeface) {
typedef SkAutoSTMalloc<128, uint16_t> SkGlyphStorage;
-static size_t force_glyph_encoding(const SkPaint& paint, const void* text,
- size_t len, SkGlyphStorage* storage,
- uint16_t** glyphIDs) {
+static int force_glyph_encoding(const SkPaint& paint, const void* text,
+ size_t len, SkGlyphStorage* storage,
+ uint16_t** glyphIDs) {
// Make sure we have a glyph id encoding.
if (paint.getTextEncoding() != SkPaint::kGlyphID_TextEncoding) {
- size_t numGlyphs = paint.textToGlyphs(text, len, NULL);
+ int numGlyphs = paint.textToGlyphs(text, len, NULL);
storage->reset(numGlyphs);
paint.textToGlyphs(text, len, storage->get());
*glyphIDs = storage->get();
@@ -145,12 +145,12 @@ static size_t force_glyph_encoding(const SkPaint& paint, const void* text,
// For user supplied glyph ids we need to validate them.
SkASSERT((len & 1) == 0);
- size_t numGlyphs = len / 2;
+ int numGlyphs = SkToInt(len / 2);
const uint16_t* input =
reinterpret_cast<uint16_t*>(const_cast<void*>((text)));
int maxGlyphID = max_glyphid_for_typeface(paint.getTypeface());
- size_t validated;
+ int validated;
for (validated = 0; validated < numGlyphs; ++validated) {
if (input[validated] > maxGlyphID) {
break;
@@ -167,7 +167,7 @@ static size_t force_glyph_encoding(const SkPaint& paint, const void* text,
memcpy(storage->get(), input, validated * sizeof(uint16_t));
}
- for (size_t i = validated; i < numGlyphs; ++i) {
+ for (int i = validated; i < numGlyphs; ++i) {
storage->get()[i] = input[i];
if (input[i] > maxGlyphID) {
storage->get()[i] = 0;
@@ -1126,8 +1126,7 @@ void SkPDFDevice::drawText(const SkDraw& d, const void* text, size_t len,
SkGlyphStorage storage(0);
uint16_t* glyphIDs = NULL;
- size_t numGlyphs = force_glyph_encoding(paint, text, len, &storage,
- &glyphIDs);
+ int numGlyphs = force_glyph_encoding(paint, text, len, &storage, &glyphIDs);
textPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
SkDrawCacheProc glyphCacheProc = textPaint.getDrawCacheProc();
@@ -1135,11 +1134,11 @@ void SkPDFDevice::drawText(const SkDraw& d, const void* text, size_t len,
content.entry()->fContent.writeText("BT\n");
set_text_transform(x, y, textPaint.getTextSkewX(),
&content.entry()->fContent);
- size_t consumedGlyphCount = 0;
+ int consumedGlyphCount = 0;
while (numGlyphs > consumedGlyphCount) {
updateFont(textPaint, glyphIDs[consumedGlyphCount], content.entry());
SkPDFFont* font = content.entry()->fState.fFont;
- size_t availableGlyphs =
+ int availableGlyphs =
font->glyphsToPDFFontEncoding(glyphIDs + consumedGlyphCount,
numGlyphs - consumedGlyphCount);
fFontGlyphUsage->noteGlyphUsage(font, glyphIDs + consumedGlyphCount,
diff --git a/src/pdf/SkPDFFont.cpp b/src/pdf/SkPDFFont.cpp
index 07ecbba37e..0d41176982 100644
--- a/src/pdf/SkPDFFont.cpp
+++ b/src/pdf/SkPDFFont.cpp
@@ -568,21 +568,21 @@ static void sk_delete_array(const void* ptr, size_t, void*) {
}
#endif
-static int get_subset_font_stream(const char* fontName,
- const SkTypeface* typeface,
- const SkTDArray<uint32_t>& subset,
- SkPDFStream** fontStream) {
+static size_t get_subset_font_stream(const char* fontName,
+ const SkTypeface* typeface,
+ const SkTDArray<uint32_t>& subset,
+ SkPDFStream** fontStream) {
int ttcIndex;
SkAutoTUnref<SkStream> fontData(typeface->openStream(&ttcIndex));
- int fontSize = fontData->getLength();
+ size_t fontSize = fontData->getLength();
#if defined (SK_SFNTLY_SUBSETTER)
// Read font into buffer.
SkPDFStream* subsetFontStream = NULL;
SkTDArray<unsigned char> originalFont;
- originalFont.setCount(fontSize);
- if (fontData->read(originalFont.begin(), fontSize) == (size_t)fontSize) {
+ originalFont.setCount(SkToInt(fontSize));
+ if (fontData->read(originalFont.begin(), fontSize) == fontSize) {
unsigned char* subsetFont = NULL;
// sfntly requires unsigned int* to be passed in, as far as we know,
// unsigned int is equivalent to uint32_t on all platforms.
@@ -765,14 +765,13 @@ bool SkPDFFont::hasGlyph(uint16_t id) {
return (id >= fFirstGlyphID && id <= fLastGlyphID) || id == 0;
}
-size_t SkPDFFont::glyphsToPDFFontEncoding(uint16_t* glyphIDs,
- size_t numGlyphs) {
+int SkPDFFont::glyphsToPDFFontEncoding(uint16_t* glyphIDs, int numGlyphs) {
// A font with multibyte glyphs will support all glyph IDs in a single font.
if (this->multiByteGlyphs()) {
return numGlyphs;
}
- for (size_t i = 0; i < numGlyphs; i++) {
+ for (int i = 0; i < numGlyphs; i++) {
if (glyphIDs[i] == 0) {
continue;
}
@@ -1112,10 +1111,10 @@ bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth,
SkASSERT(subset);
// Font subsetting
SkPDFStream* rawStream = NULL;
- int fontSize = get_subset_font_stream(fontInfo()->fFontName.c_str(),
- typeface(),
- *subset,
- &rawStream);
+ size_t fontSize = get_subset_font_stream(fontInfo()->fFontName.c_str(),
+ typeface(),
+ *subset,
+ &rawStream);
SkASSERT(fontSize);
SkASSERT(rawStream);
SkAutoTUnref<SkPDFStream> fontStream(rawStream);
diff --git a/src/pdf/SkPDFFont.h b/src/pdf/SkPDFFont.h
index 68a00f079a..3a5234d264 100644
--- a/src/pdf/SkPDFFont.h
+++ b/src/pdf/SkPDFFont.h
@@ -111,7 +111,7 @@ public:
* @param numGlyphs The number of input glyphs.
* @return Returns the number of glyphs consumed.
*/
- size_t glyphsToPDFFontEncoding(uint16_t* glyphIDs, size_t numGlyphs);
+ int glyphsToPDFFontEncoding(uint16_t* glyphIDs, int numGlyphs);
/** Get the font resource for the passed typeface and glyphID. The
* reference count of the object is incremented and it is the caller's
diff --git a/src/pdf/SkPDFTypes.h b/src/pdf/SkPDFTypes.h
index 5ed6386bdd..1f06c4c5fe 100644
--- a/src/pdf/SkPDFTypes.h
+++ b/src/pdf/SkPDFTypes.h
@@ -392,6 +392,14 @@ public:
*/
void insertInt(const char key[], int32_t value);
+ /**
+ * Calls insertInt() but asserts in debug builds that the value can be represented
+ * by an int32_t.
+ */
+ void insertInt(const char key[], size_t value) {
+ this->insertInt(key, SkToS32(value));
+ }
+
/** Add the scalar to the dictionary with the given key.
* @param key The text of the key for this dictionary entry.
* @param value The scalar value for this dictionary entry.