diff options
author | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2016-01-20 15:35:01 +0000 |
---|---|---|
committer | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2016-01-20 15:35:01 +0000 |
commit | 415a631440d99d1c3d7f4f236c03bc34a265052b (patch) | |
tree | 64a29c012f171b8c81487e83879a7fb6cc8e98cf /Build/source/texk/dvisvgm/dvisvgm-src/src/ColorSpecialHandler.cpp | |
parent | 42d0780e54824483b089636e0b88fd3546d1f060 (diff) |
dvisvgm 1.14.2
git-svn-id: svn://tug.org/texlive/trunk@39435 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/dvisvgm/dvisvgm-src/src/ColorSpecialHandler.cpp')
-rw-r--r-- | Build/source/texk/dvisvgm/dvisvgm-src/src/ColorSpecialHandler.cpp | 73 |
1 files changed, 35 insertions, 38 deletions
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/ColorSpecialHandler.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/ColorSpecialHandler.cpp index 3b8681de94c..f61de4768ca 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/src/ColorSpecialHandler.cpp +++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/ColorSpecialHandler.cpp @@ -19,10 +19,7 @@ *************************************************************************/ #include <config.h> -#include <algorithm> -#include <cmath> #include <cstring> -#include <iomanip> #include <sstream> #include <vector> #include "ColorSpecialHandler.h" @@ -51,18 +48,16 @@ static void read_doubles (istream &is, vector<double> &v) { } -/** Reads a color statement from an input stream and converts it to RGB. +/** Reads a color statement from an input stream and converts it to a color object. * A color statement has the following syntax: * _color model_ _component values_ * Currently, the following color models are supported: rgb, cmyk, hsb and gray. * Examples: rgb 1 0.5 0, gray 0.5 - * @param[in] model if model != "" this value specifies the model, otherwise it's read from the stream + * @param[in] model the color model * @param[in] is stream to be read from - * @param[out] color italicresulting RGB triple - * @return true if statement has successfully been read */ -static void read_color (string model, istream &is, Color &color) { - if (model.empty()) - is >> model; + * @return resulting Color object */ +Color ColorSpecialHandler::readColor (const string &model, istream &is) { + Color color; if (model == "rgb") { vector<double> rgb(3); read_doubles(is, rgb); @@ -82,38 +77,40 @@ static void read_color (string model, istream &is, Color &color) { color.setGray(read_double(is)); else if (!color.setPSName(model, true)) throw SpecialException("unknown color statement"); + return color; } -bool ColorSpecialHandler::process (const char *prefix, istream &is, SpecialActions *actions) { - Color color; - if (prefix && strcmp(prefix, "background") == 0) { - read_color("", is, color); - actions->setBgColor(color); +/** Reads the color model (rgb, cmyk, hsb, or gray) and the corresponding color compontents + * from a given input stream. + * @param[in] is stream to be read from + * @return resulting Color object */ +Color ColorSpecialHandler::readColor (istream &is) { + string model; + is >> model; + return readColor(model, is); +} + + +bool ColorSpecialHandler::process (const char*, istream &is, SpecialActions *actions) { + string cmd; + is >> cmd; + if (cmd == "push") // color push <model> <params> + _colorStack.push(readColor(is)); + else if (cmd == "pop") { + if (!_colorStack.empty()) // color pop + _colorStack.pop(); + } + else { // color <model> <params> + while (!_colorStack.empty()) + _colorStack.pop(); + _colorStack.push(readColor(cmd, is)); } - else { - string cmd; - is >> cmd; - if (cmd == "push") { // color push <model> <params> - read_color("", is, color); - _colorStack.push(color); - } - else if (cmd == "pop") { - if (!_colorStack.empty()) // color pop - _colorStack.pop(); - } - else { // color <model> <params> - read_color(cmd, is, color); - while (!_colorStack.empty()) - _colorStack.pop(); - _colorStack.push(color); - } - if (actions) { - if (_colorStack.empty()) - actions->setColor(Color::BLACK); - else - actions->setColor(_colorStack.top()); - } + if (actions) { + if (_colorStack.empty()) + actions->setColor(Color::BLACK); + else + actions->setColor(_colorStack.top()); } return true; } |