forked from adlr/PDFSketch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphic_factory.cc
61 lines (53 loc) · 1.58 KB
/
graphic_factory.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright...
#include "graphic_factory.h"
#include "circle.h"
#include "checkmark.h"
#include "rectangle.h"
#include "squiggle.h"
#include "text_area.h"
using std::make_shared;
using std::shared_ptr;
using std::string;
namespace pdfsketch {
std::shared_ptr<Graphic> GraphicFactory::NewGraphic(
const Toolbox::Tool& type) {
switch (type) {
case Toolbox::ARROW:
return shared_ptr<Graphic>(NULL);
case Toolbox::TEXT:
return make_shared<TextArea>();
case Toolbox::CIRCLE:
return make_shared<Circle>();
case Toolbox::RECTANGLE:
return make_shared<Rectangle>();
case Toolbox::SQUIGGLE:
return make_shared<Squiggle>();
case Toolbox::CHECKMARK:
return make_shared<Checkmark>();
}
printf("%s: should not get to here\n", __func__);
return shared_ptr<Graphic>(NULL);
}
std::shared_ptr<Graphic> GraphicFactory::NewGraphic(
const pdfsketchproto::Graphic& msg) {
switch (msg.type()) {
case pdfsketchproto::Graphic::TEXT:
return make_shared<TextArea>(msg);
case pdfsketchproto::Graphic::CIRCLE:
return make_shared<Circle>(msg);
case pdfsketchproto::Graphic::RECTANGLE:
return make_shared<Rectangle>(msg);
case pdfsketchproto::Graphic::SQUIGGLE:
return make_shared<Squiggle>(msg);
case pdfsketchproto::Graphic::CHECKMARK:
return make_shared<Checkmark>(msg);
}
return shared_ptr<Graphic>(NULL);
}
std::shared_ptr<Graphic> GraphicFactory::NewText(
const string& str) {
std::shared_ptr<TextArea> ret(make_shared<TextArea>());
ret->set_text(str);
return ret;
}
} // namespace pdfsketch