Annotation of parser3/src/types/pa_vimage.C, revision 1.42
1.7 paf 1: /** @file
1.1 paf 2: Parser: @b image parser type.
3:
1.41 moko 4: Copyright (c) 2001-2012 Art. Lebedev Studio (http://www.artlebedev.com)
1.16 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.18 paf 6: */
1.1 paf 7:
8: #include "pa_vimage.h"
9: #include "pa_vint.h"
10: #include "pa_vstring.h"
1.8 parser 11: #include "gif.h"
1.36 misha 12: #include "pa_vbool.h"
13:
1.42 ! moko 14: volatile const char * IDENT_PA_VIMAGE_C="$Id: pa_vimage.C,v 1.41 2012-03-16 09:24:17 moko Exp $" IDENT_PA_VIMAGE_H;
1.1 paf 15:
1.23 paf 16: void VImage::set(const String* src, int width, int height,
1.21 paf 17: gdImage* aimage,
18: Value* aexif) {
1.30 paf 19: fimage=aimage;
1.21 paf 20: fexif=aexif;
1.3 paf 21:
1.1 paf 22: // $src
1.3 paf 23: if(src)
1.28 paf 24: ffields.put(String::Body("src"), new VString(*src));
1.1 paf 25: // $width
26: if(width)
1.28 paf 27: ffields.put(String::Body("width"), new VInt(width));
1.1 paf 28: // $height
29: if(height)
1.28 paf 30: ffields.put(String::Body("height"), new VInt(height));
1.2 paf 31: // defaults
1.8 parser 32: // $border(0)
1.28 paf 33: ffields.put(String::Body("border"), new VInt(0));
1.11 parser 34:
1.12 parser 35: // internals, take a look at image.C append_attrib_pair before update
1.8 parser 36: // $line-width(1)
1.28 paf 37: ffields.put(String::Body("line-width"), new VInt(1));
1.8 parser 38: }
39:
1.42 ! moko 40: Value& VImage::as_expr_result() {
1.37 misha 41: return VBool::get(as_bool());
1.36 misha 42: }
43:
1.21 paf 44:
1.40 misha 45: Value* VImage::get_element(const String& aname) {
1.21 paf 46: // $method
1.40 misha 47: if(Value* result=VStateless_object::get_element(aname))
1.21 paf 48: return result;
49:
50: // $exif
51: if(aname==EXIF_ELEMENT_NAME)
52: return fexif;
53:
54: // $src, $size
1.23 paf 55: return ffields.get(aname);
1.21 paf 56: }
1.8 parser 57:
1.40 misha 58: const VJunction* VImage::put_element(const String& aname, Value* avalue, bool /*replace*/) {
1.8 parser 59: ffields.put(aname, avalue);
60:
1.30 paf 61: if(fimage) {
1.8 parser 62: if(aname=="line-width") {
1.30 paf 63: fimage->SetLineWidth(min(max(avalue->as_int(), 1), 10));
1.8 parser 64: } else if(aname=="line-style") {
1.23 paf 65: const String& sline_style=avalue->as_string();
1.39 misha 66: fimage->SetLineStyle(sline_style.length()?sline_style.taint_cstr(String::L_AS_IS):0);
1.8 parser 67: }
1.20 paf 68: }
69:
1.31 paf 70: return PUT_ELEMENT_REPLACED_ELEMENT;
1.1 paf 71: }
E-mail: