# class Cairo::Win32Surface

Win32 surface

### Public Class Methods

new(*args) click to toggle source

Win32 surface functions

    static VALUE
    cr_win32_surface_initialize (int argc, VALUE *argv, VALUE self)
    {
      cairo_surface_t *surface = NULL;
      VALUE arg1, arg2, arg3, arg4;
      VALUE hdc, format, width, height;

      rb_scan_args (argc, argv, "13", &arg1, &arg2, &arg3, &arg4);

      switch (argc)
        {
        case 1:
          hdc = arg1;
          surface = cairo_win32_surface_create (NUM2PTR (hdc));
          break;
        case 2:
    #  if CAIRO_CHECK_VERSION(1, 11, 4)
    #    define CAIRO_FORMAT_MAX CAIRO_FORMAT_RGB30
    #  else
    #    define CAIRO_FORMAT_MAX CAIRO_FORMAT_RGB16_565
    #  endif
          if (CAIRO_FORMAT_ARGB32 <= NUM2INT (arg2) &&
              NUM2INT (arg2) <= CAIRO_FORMAT_MAX)
            {
    #  if CAIRO_CHECK_VERSION(1, 15, 2)
              hdc = arg1;
              format = arg2;
              surface =
                cairo_win32_surface_create_with_format (NUM2PTR (hdc),
                                                        RVAL2CRFORMAT (format));
    #  else
              rb_raise (rb_eArgError,
                        "Cairo::Win32Surface.new(hdc, format) "
                        "is available since cairo >= 1.15.2");
    #  endif
            }
          else
            {
              width = arg1;
              height = arg2;
              surface = cairo_win32_surface_create_with_dib (CAIRO_FORMAT_ARGB32,
                                                             NUM2INT (width),
                                                             NUM2INT (height));
            }
          break;
        case 3:
          if (NIL_P (arg1) ||
              (rb_cairo__is_kind_of (arg1, rb_cNumeric) &&
               NUM2INT (arg1) != CAIRO_FORMAT_RGB24))
            {
    #  if CAIRO_CHECK_VERSION(1, 4, 0)
              HDC win32_hdc;
              hdc = arg1;
              width = arg2;
              height = arg3;
              win32_hdc = NIL_P (hdc) ? NULL : NUM2PTR (hdc);
              surface = cairo_win32_surface_create_with_ddb (win32_hdc,
                                                             CAIRO_FORMAT_RGB24,
                                                             NUM2INT (width),
                                                             NUM2INT (height));
    #  else
              rb_raise (rb_eArgError,
                        "Cairo::Win32Surface.new(hdc, width, height) "
                        "is available since cairo >= 1.4.0");
    #  endif
            }
          else
            {
              format = arg1;
              width = arg2;
              height = arg3;
              surface = cairo_win32_surface_create_with_dib (RVAL2CRFORMAT (format),
                                                             NUM2INT (width),
                                                             NUM2INT (height));
            }
          break;
        case 4:
          {
    #  if CAIRO_CHECK_VERSION(1, 4, 0)
            HDC win32_hdc;
            hdc = arg1;
            format = arg2;
            width = arg3;
            height = arg4;
            win32_hdc = NIL_P (hdc) ? NULL : (HDC) NUM2UINT (hdc);
            surface = cairo_win32_surface_create_with_ddb (win32_hdc,
                                                           RVAL2CRFORMAT (format),
                                                           NUM2INT (width),
                                                           NUM2INT (height));
    #  else
            rb_raise (rb_eArgError,
                      "Cairo::Win32Surface.new(hdc, format, width, height) "
                      "is available since cairo >= 1.4.0");
    #  endif
          }
          break;
        }

      if (!surface)
        rb_cairo_check_status (CAIRO_STATUS_INVALID_FORMAT);
      rb_cairo_surface_check_status (surface);
      DATA_PTR (self) = surface;
      if (rb_block_given_p ())
        rb_cairo__surface_yield_and_finish (self);
      return Qnil;
    }

### Public Instance Methods

hdc() click to toggle source

    static VALUE
    cr_win32_surface_get_hdc (VALUE self)
    {
      HDC hdc;

      hdc = cairo_win32_surface_get_dc (_SELF);
      if (!hdc)
        return Qnil;
      else
        return PTR2NUM (hdc);
    }

image() click to toggle source

    static VALUE
    cr_win32_surface_get_image (VALUE self)
    {
      cairo_surface_t *surface;

      surface = cairo_win32_surface_get_image (_SELF);
      if (!surface)
        return Qnil;
      rb_cairo_surface_check_status (surface);
      return CRSURFACE2RVAL (surface);
    }