blob: 26788ee1ed70be739a2a761ccf8d70ce953bccec [file] [log] [blame]
twiz@google.com6cf53032012-06-22 18:55:55 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "picture_utils.h"
9#include "SkBitmap.h"
10#include "SkPicture.h"
11#include "SkString.h"
12#include "SkStream.h"
13
14namespace sk_tools {
15
keyar@chromium.org1cbd47c2012-07-13 18:22:59 +000016 void make_filepath(SkString* path, const SkString& dir, const SkString& name) {
17 size_t len = dir.size();
twiz@google.com6cf53032012-06-22 18:55:55 +000018 path->set(dir);
19 if (0 < len && '/' != dir[len - 1]) {
20 path->append("/");
21 }
22 path->append(name);
23 }
24
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +000025 namespace {
26 bool is_path_seperator(const char chr) {
27#if defined(SK_BUILD_FOR_WIN)
28 return chr == '\\' || chr == '/';
29#else
30 return chr == '/';
31#endif
32 }
33 }
34
35 void get_basename(SkString* basename, const SkString& path) {
36 if (path.size() == 0) {
37 basename->reset();
38 return;
39 }
40
41 size_t end = path.size() - 1;
42
43 // Paths pointing to directories often have a trailing slash,
44 // we remove it so the name is not empty
45 if (is_path_seperator(path[end])) {
46 if (end == 0) {
47 basename->reset();
48 return;
49 }
50
51 end -= 1;
52 }
53
54 size_t i = end;
55 do {
56 --i;
57 if (is_path_seperator(path[i])) {
58 const char* basenameStart = path.c_str() + i + 1;
59 size_t basenameLength = end - i;
60 basename->set(basenameStart, basenameLength);
61 return;
62 }
63 } while (i > 0);
64
65 basename->set(path.c_str(), end + 1);
66 }
67
keyar@chromium.org163b5672012-08-01 17:53:29 +000068 bool is_percentage(char* const string) {
69 SkString skString(string);
70 return skString.endsWith("%");
71 }
72
twiz@google.com6cf53032012-06-22 18:55:55 +000073 void setup_bitmap(SkBitmap* bitmap, int width, int height) {
74 bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height);
75 bitmap->allocPixels();
76 bitmap->eraseColor(0);
77 }
78
79}