get a canvas for drawing, prepared according to settings

@see #draw(com.itextpdf.text.Rectangle, java.lang.String)
@return
962404
protected final PdfContentByte getPreparedCanvas(float opacity) {
      needRestore = false;
      PdfContentByte canvas = (tableForeground != null) ? tableForeground : (isBg())
          ? getWriter().getDirectContentUnder()
          : getWriter().getDirectContent();
      String layerName = getLayerName();
      BLENDMODE blend = getBlend();
      if (getWriter().getPDFXConformance() == PdfWriter.PDFX1A2001) {
         // check blend, opacity, layers
         if (!PdfGState.BM_NORMAL.equals(blend.getBlend()) && !PdfGState.BM_COMPATIBLE.equals(blend.getBlend())) {
            throw new VectorPrintRuntimeException("blend not supported in PDF/X-1a: " + blend);
         }
         if (layerName != null) {
            throw new VectorPrintRuntimeException("layers not supported in PDF/X-1a: " + layerName);
         }
         if (opacity < 1) {
            throw new VectorPrintRuntimeException("opacity not supported in PDF/X-1a: " + opacity);
         }
      }
      if (layerName != null) {
         layerManager.startLayerInGroup(layerName, canvas);
      }
//					 pgs.setAlphaIsShape(true);
      if (opacity <= 1) {
//								PdfShading shading = PdfShading.simpleAxial(getWriter(), 0, 0, getDocument().right() - getDocument().getPageSize().getWidth() * 0.6f, getDocument().top() - getDocument().getPageSize().getHeight() * 0.6f, Color.green, Color.orange,true,true);
//								canvas.paintShading(shading);
         canvas.saveState();
         needRestore = true;
         PdfGState pgs = new PdfGState();
         pgs.setFillOpacity(opacity);
         pgs.setStrokeOpacity(opacity);
         canvas.setGState(pgs);
      }
      if (!BLENDMODE.NORMAL.equals(blend)) {
         if (!needRestore) {
            canvas.saveState();
            needRestore = true;
         }
         PdfGState pgs = new PdfGState();
         pgs.setBlendMode(blend.getBlend());
         canvas.setGState(pgs);
      }
      if (getTransform() != null && !(this instanceof Image)) {
         canvas.transform(new AffineTransform(getTransform()));
      }
      return canvas;
   }
454121
function Canvas(width, height, buffer) {
    width  = _.defaults(width , 640)|0;
    height = _.defaults(height, 400)|0;

    if (Canvas.isCanvasRGB(width, height, buffer)) {
      return new CanvasRGB(width, height, buffer);
    }
    if (Canvas.isCanvasRGBA(width, height, buffer)) {
      return new CanvasRGBA(width, height, buffer);
    }

    var $ = dollar(width, height, 1, buffer);

    $.putPixel = function(x, y, color) {
      var index = y * width + x;

      if ($.mask && $.mask[index] === 0) {
        return;
      }

      var colorIndex = color.valueOf(x, y);

      if (colorIndex !== -1) {
        $.data[index] = colorIndex & 15;
      }
    };

    this.$ = $;
  }
1005212
private void draw() throws GeometryIndexNotFoundException {
		if (Geometry.POINT.equals(editService.getGeometry().getGeometryType())) {
			drawPoint(null);
		} else if (Geometry.LINE_STRING.equals(editService.getGeometry().getGeometryType())
				|| Geometry.LINEAR_RING.equals(editService.getGeometry().getGeometryType())) {
			drawLineString(null);
		} else if (Geometry.POLYGON.equals(editService.getGeometry().getGeometryType())) {
			drawPolygon(null);
		}
	}
701320
public static Drawable getDrawableAttr(Context ctx, @AttrRes int drawableAttrId){
        int[] attrs = new int[] { drawableAttrId /* index 0 */};
        TypedArray ta = ctx.obtainStyledAttributes(attrs);
        Drawable drawable = ta.getDrawable(0);
        ta.recycle();
        return drawable;
    }
280308
public Bitmap getViewBitmap() {
        if (view!=null)
            return null;
        Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);

        view.layout(view.getLeft(), view.getTop(), view.getRight(), view.getBottom());
        view.draw(canvas);

        return bitmap;
    }
442233
function draw(texture, width, height) {
  if (!this._.isInitialized || texture._.width != this.width || texture._.height != this.height) {
    initialize.call(this, width ? width : texture._.width, height ? height : texture._.height);
  }

  texture._.use();
  this._.texture.drawTo(function() {
    Shader.getDefaultShader().drawRect();
  });

  return this;
}
459288
private void generatePatternBitmap() {
    if (getBounds().width() <= 0 || getBounds().height() <= 0) {
      return;
    }

    bitmap = Bitmap.createBitmap(getBounds().width(), getBounds().height(), Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);

    Rect r = new Rect();
    boolean verticalStartWhite = true;
    for (int i = 0; i <= numRectanglesVertical; i++) {
      boolean isWhite = verticalStartWhite;
      for (int j = 0; j <= numRectanglesHorizontal; j++) {
        r.top = i * rectangleSize;
        r.left = j * rectangleSize;
        r.bottom = r.top + rectangleSize;
        r.right = r.left + rectangleSize;
        canvas.drawRect(r, isWhite ? paintWhite : paintGray);
        isWhite = !isWhite;
      }
      verticalStartWhite = !verticalStartWhite;
    }
  }
100730
def draw_foreground
      # Always roll back changes made by the user unless the text is editable.
      if editable? or text == @old_text
        recalc if focused? # Workaround for Windows draw/update bug.
        @old_caret_position = caret_position
        @old_selection_start = @text_input.selection_start
      else
        roll_back
      end

      if caret_position > stripped_text.length
        self.caret_position = stripped_text.length
      end

      if @text_input.selection_start >= stripped_text.length
        @text_input.selection_start = stripped_text.length
      end

      # Draw the selection.
      selection_range.each do |pos|
        char_x, char_y = @caret_positions[pos]
        char_width = @char_widths[pos]
        left, top = x + padding_left + char_x, y + padding_top + char_y
        draw_rect left, top, char_width, font.height, z, @selection_color
      end

      # Draw text.
      @lines.each_with_index do |line, index|
        font.draw(line, x + padding_left, y + padding_top + y_at_line(index), z)
      end

      # Draw the caret.
      if focused? and ((Gosu::milliseconds / @caret_period) % 2 == 0)
        caret_x, caret_y = @caret_positions[caret_position]
        left, top = x + padding_left + caret_x, y + padding_top + caret_y
        draw_rect left, top, 1, font.height, z, @caret_color
      end
    end
263507
@Override
    public void draw() {
        if (googleRenderer == null)  {
            getPresenter().showError(new ClientRuntimeError("Google renderer not set"));
        }
        else if (!getPresenter().isDrawn())  {
            List<Displayer> displayerList = new ArrayList<Displayer>();
            displayerList.add(getPresenter());
            googleRenderer.draw(displayerList);
        }
    }
318784
public void onDraw(final Canvas canvas) {
    mPaint.setColor(0xC0000000);
    mTextRect.set(0, 0, mView.getWidth(), 35);
    canvas.drawRect(mTextRect, mPaint);

    mPaint.setColor(Color.WHITE);
    canvas.drawText("[" + mTag + "]", 10, 15, mPaint);

    String message = "Not started";
    switch (mState) {
      case STARTED:
        message = "Loading...";
        break;
      case SUCCESS:
        message = "Loaded after " + (mFinishTime - mStartTime) + "ms";
        break;
      case FAILURE:
        message = "Failed after " + (mFinishTime - mStartTime) + "ms";
        break;
      case CANCELLATION:
        message = "Cancelled after " + (mFinishTime - mStartTime) + "ms";
        break;
    }
    canvas.drawText(message, 10, 30, mPaint);
  }
498875
private Rectangle2D getBoundsHint() {

    if (chart.getStyler().isChartTitleVisible() && chart.getTitle().length() > 0) {

      TextLayout textLayout =
          new TextLayout(
              chart.getTitle(),
              chart.getStyler().getChartTitleFont(),
              new FontRenderContext(null, true, false));
      Rectangle2D rectangle = textLayout.getBounds();
      double width = 2 * chart.getStyler().getChartTitlePadding() + rectangle.getWidth();
      double height = 2 * chart.getStyler().getChartTitlePadding() + rectangle.getHeight();

      return new Rectangle2D.Double(
          Double.NaN, Double.NaN, width, height); // Double.NaN indicates not sure yet.
    } else {
      return new Rectangle2D
          .Double(); // Constructs a new Rectangle2D, initialized to location (0, 0) and size (0,
      // 0).
    }
  }
1187549
protected static Rectangle getRectangle (BufferedImage img, boolean stretch)
    {
        Rectangle rect = new Rectangle(0, 0, img.getWidth() - 2, img.getHeight() - 2);

        for (int xx = 1; xx < rect.width + 1; xx++) {
            if (ImageUtil.hitTest(img, xx, stretch ? 0 : img.getHeight() - 1)) {
                rect.x = xx - 1;
                rect.width -= rect.x;
                break;
            }
        }

        for (int xx = img.getWidth() - 1; xx >= rect.x + 1; xx--) {
            if (ImageUtil.hitTest(img, xx, stretch ? 0 : img.getHeight() - 1)) {
                rect.width = xx - rect.x;
                break;
            }
        }

        for (int yy = 1; yy < rect.height + 1; yy++) {
            if (ImageUtil.hitTest(img, stretch ? 0 : img.getWidth() - 1, yy)) {
                rect.y = yy - 1;
                rect.height -= rect.y;
                break;
            }
        }

        for (int yy = img.getHeight() - 1; yy >= rect.y + 1; yy--) {
            if (ImageUtil.hitTest(img, stretch ? 0 : img.getWidth() - 1, yy)) {
                rect.height = yy - rect.y;
                break;
            }
        }

        return rect;
    }
555908
def draw(self):
        

        logger.debug("*** draw")

        if not self.text:
            return

        canvas = self.canv
        style = self.style

        canvas.saveState()

        # Draw box arround paragraph for debugging
        if self.debug:
            bw = 0.5
            bc = Color(1, 1, 0)
            bg = Color(0.9, 0.9, 0.9)
            canvas.setStrokeColor(bc)
            canvas.setLineWidth(bw)
            canvas.setFillColor(bg)
            canvas.rect(
                style.leftIndent,
                0,
                self.width,
                self.height,
                fill=1,
                stroke=1)

        y = 0
        dy = self.height
        for line in self.text.lines:
            y += line.height
            for frag in line:

                # Box
                if hasattr(frag, "draw"):
                    frag.draw(canvas, dy - y)

                # Text
                if frag.get("text", ""):
                    canvas.setFont(frag["fontName"], frag["fontSize"])
                    canvas.setFillColor(frag.get("color", style["color"]))
                    canvas.drawString(frag["x"], dy - y + frag["y"], frag["text"])

                # XXX LINK
                link = frag.get("link", None)
                if link:
                    _scheme_re = re.compile('^[a-zA-Z][-+a-zA-Z0-9]+$')
                    x, y, w, h = frag["x"], dy - y, frag["width"], frag["fontSize"]
                    rect = (x, y, w, h)
                    if isinstance(link, six.text_type):
                        link = link.encode('utf8')
                    parts = link.split(':', 1)
                    scheme = len(parts) == 2 and parts[0].lower() or ''
                    if _scheme_re.match(scheme) and scheme != 'document':
                        kind = scheme.lower() == 'pdf' and 'GoToR' or 'URI'
                        if kind == 'GoToR':
                            link = parts[1]

                        canvas.linkURL(link, rect, relative=1, kind=kind)
                    else:
                        if link[0] == '#':
                            link = link[1:]
                            scheme = ''
                        canvas.linkRect("", scheme != 'document' and link or parts[1], rect, relative=1)

        canvas.restoreState()
1346537
public BufferedImage getBufferedImage()
    {
        if (image == null || abort)
            return null;
        
        // no container that would repaint -- wait for the complete image
        if (container == null)
            waitForLoad();
        
        BufferedImage img = new BufferedImage(getIntrinsicWidth(), getIntrinsicHeight(), BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = img.createGraphics();
        g.drawImage(image, null, null);
        g.dispose();

        return img;
    }
308036
@Override
    protected synchronized void onDraw(@NonNull Canvas canvas) {
        super.onDraw(canvas);

        paint.setTextSize(textSize);
        paint.setStyle(Style.FILL);
        paint.setColor(defaultColor);
        paint.setAntiAlias(true);
        float minMaxLabelSize = 0;

        if (showLabels) {
            // draw min and max labels
            String minLabel = getContext().getString(R.string.demo_min_label);
            String maxLabel = getContext().getString(R.string.demo_max_label);
            minMaxLabelSize = Math.max(paint.measureText(minLabel), paint.measureText(maxLabel));
            float minMaxHeight = textOffset + thumbHalfHeight + textSize / 3;
            canvas.drawText(minLabel, 0, minMaxHeight, paint);
            canvas.drawText(maxLabel, getWidth() - minMaxLabelSize, minMaxHeight, paint);
        }
        padding = internalPad + minMaxLabelSize + thumbHalfWidth;

        // draw seek bar background line
        rect.left = padding;
        rect.right = getWidth() - padding;
        canvas.drawRect(rect, paint);

        boolean selectedValuesAreDefault = (normalizedMinValue <= minDeltaForDefault && normalizedMaxValue >= 1 - minDeltaForDefault);

        int colorToUseForButtonsAndHighlightedLine = !alwaysActive && !activateOnDefaultValues && selectedValuesAreDefault ?
                defaultColor : // default values
                activeColor;   // non default, filter is active

        // draw seek bar active range line
        rect.left = normalizedToScreen(normalizedMinValue);
        rect.right = normalizedToScreen(normalizedMaxValue);

        paint.setColor(colorToUseForButtonsAndHighlightedLine);
        canvas.drawRect(rect, paint);

        // draw minimum thumb (& shadow if requested) if not a single thumb control
        if (!singleThumb) {
            if (thumbShadow) {
                drawThumbShadow(normalizedToScreen(normalizedMinValue), canvas);
            }
            drawThumb(normalizedToScreen(normalizedMinValue), Thumb.MIN.equals(pressedThumb), canvas,
                    selectedValuesAreDefault);
        }

        // draw maximum thumb & shadow (if necessary)
        if (thumbShadow) {
            drawThumbShadow(normalizedToScreen(normalizedMaxValue), canvas);
        }
        drawThumb(normalizedToScreen(normalizedMaxValue), Thumb.MAX.equals(pressedThumb), canvas,
                selectedValuesAreDefault);

        // draw the text if sliders have moved from default edges
        if (showTextAboveThumbs && (activateOnDefaultValues || !selectedValuesAreDefault)) {
            paint.setTextSize(textSize);
            paint.setColor(textAboveThumbsColor);

            String minText = valueToString(getSelectedMinValue());
            String maxText = valueToString(getSelectedMaxValue());
            float minTextWidth = paint.measureText(minText);
            float maxTextWidth = paint.measureText(maxText);
            // keep the position so that the labels don't get cut off
            float minPosition = Math.max(0f, normalizedToScreen(normalizedMinValue) - minTextWidth * 0.5f);
            float maxPosition = Math.min(getWidth() - maxTextWidth, normalizedToScreen(normalizedMaxValue) - maxTextWidth * 0.5f);

            if (!singleThumb) {
                // check if the labels overlap, or are too close to each other
                int spacing = PixelUtil.dpToPx(getContext(), TEXT_LATERAL_PADDING_IN_DP);
                float overlap = minPosition + minTextWidth - maxPosition + spacing;
                if (overlap > 0f) {
                    // we could move them the same ("overlap * 0.5f")
                    // but we rather move more the one which is farther from the ends, as it has more space
                    minPosition -= overlap * normalizedMinValue / (normalizedMinValue + 1-normalizedMaxValue);
                    maxPosition += overlap * (1-normalizedMaxValue) / (normalizedMinValue + 1-normalizedMaxValue);
                }
                canvas.drawText(minText,
                        minPosition,
                        distanceToTop + textSize,
                        paint);

            }

            canvas.drawText(maxText,
                    maxPosition,
                    distanceToTop + textSize,
                    paint);
        }

    }
60060
function() {
        var div = OpenLayers.Control.Panel.prototype.draw.apply(this, arguments);
        if (this.defaultControl === null) {
            this.defaultControl = this.controls[0];
        }
        return div;
    }
1228644
@Override
    public final Scene draw()
    {
        final NFastArrayList<Layer> layers = getChildNodes();

        if (null != layers)
        {
            final int size = layers.size();

            for (int i = 0; i < size; i++)
            {
                final Layer layer = layers.get(i);

                if (null != layer)
                {
                    layer.draw();
                }
            }
        }
        return this;
    }