private Rectangle getGlyphBounds (GlyphVector vector, int index, int codePoint) { Rectangle bounds; bounds = vector.getGlyphPixelBounds(index, GlyphPage.renderContext, 0, 0); if (renderType == RenderType.Native) { if (bounds.width == 0 || bounds.height == 0) bounds = new Rectangle(); else bounds = metrics.getStringBounds("" + (char)codePoint, GlyphPage.scratchGraphics).getBounds(); } if (codePoint == ' ') bounds.width = spaceWidth; return bounds; }
private Rectangle getGlyphBounds (GlyphVector vector, int index, int codePoint) { Rectangle bounds; bounds = vector.getGlyphPixelBounds(index, GlyphPage.renderContext, 0, 0); if (renderType == RenderType.Native) { if (bounds.width == 0 || bounds.height == 0) bounds = new Rectangle(); else bounds = metrics.getStringBounds("" + (char)codePoint, GlyphPage.scratchGraphics).getBounds(); } if (codePoint == ' ') bounds.width = spaceWidth; return bounds; }
private void draw (Graphics g, Array<TextureRegion> regions, Color color, boolean drawIndex) { int i=0; for(TextureRegion region : regions){ int x = region.getRegionX(), y = region.getRegionY(), h = region.getRegionHeight(); if(drawIndex){ String indexString = ""+i; Rectangle bounds = g.getFontMetrics().getStringBounds(indexString, g).getBounds(); g.setColor(indexBackgroundColor); g.fillRect(x, y+h-bounds.height, bounds.width, bounds.height); g.setColor(indexColor); g.drawString(indexString, x, y+h); ++i; } g.setColor(color); g.drawRect(x, y, region.getRegionWidth(), h); } } }
private void draw (Graphics g, Array<TextureRegion> regions, Color color, boolean drawIndex) { int i=0; for(TextureRegion region : regions){ int x = region.getRegionX(), y = region.getRegionY(), h = region.getRegionHeight(); if(drawIndex){ String indexString = ""+i; Rectangle bounds = g.getFontMetrics().getStringBounds(indexString, g).getBounds(); g.setColor(indexBackgroundColor); g.fillRect(x, y+h-bounds.height, bounds.width, bounds.height); g.setColor(indexColor); g.drawString(indexString, x, y+h); ++i; } g.setColor(color); g.drawRect(x, y, region.getRegionWidth(), h); } } }
double getStringWidth(String text, Font font) { return font.getStringBounds(text, 0, text.length(), gd.getFontRenderContext()).getBounds().getWidth(); }
private void drawStraightLabelLine( java.awt.Shape outline, boolean drawingHalo, float thickness, float offset) { Rectangle2D bounds = outline.getBounds2D().getBounds(); double minX = bounds.getMinX(); double maxX = bounds.getMaxX(); if ((Math.abs(maxX - minX) < 0.0000001)) { // nothing to draw return; } // let's se if we are drawing the halo around the underline line if (drawingHalo) { // when drawing the halo we assume that the correct halo configuration has been set graphics.draw(new Line2D.Double(minX, offset, maxX, offset)); } else { // storing the current stroke and setting the stroke according to the specified // thickness Stroke currentStroke = graphics.getStroke(); graphics.setStroke(new BasicStroke(thickness)); // we draw a line with the same color of the text and a stroke of 2 graphics.draw(new Line2D.Double(minX, offset, maxX, offset)); // we need to restore the previous stroke graphics.setStroke(currentStroke); } }
/** * Return a crop region from a specified envelope, leveraging on a grid to world transformation. * * @param envelope the crop envelope * @param gridToWorldTransform the grid2world transformation * @return a {@code Rectangle} representing the crop region. * @throws TransformException in case a problem occurs when going back to raster space. */ public static Rectangle getCropRegion( GeneralEnvelope envelope, final MathTransform gridToWorldTransform) throws TransformException { if (envelope == null || gridToWorldTransform == null) { boolean isEnvelope = envelope == null; boolean isG2W = gridToWorldTransform == null; boolean twoErrors = isEnvelope && isG2W; final StringBuilder errorMessage = new StringBuilder(); errorMessage .append("Specified ") .append(isEnvelope ? "envelope" : "") .append(twoErrors ? ", " : "") .append(isG2W ? "grid to world transformation " : "") .append("is null"); throw new IllegalArgumentException(errorMessage.toString()); } final MathTransform worldToGridTransform = gridToWorldTransform.inverse(); final GeneralEnvelope rasterArea = CRS.transform(worldToGridTransform, envelope); final Rectangle2D ordinates = rasterArea.toRectangle2D(); return ordinates.getBounds(); }
/** * This method is responsible for computing the raster bounds of the final mosaic. * * @throws TransformException In case transformation fails during the process. */ private void initRasterBounds() throws TransformException { final GeneralEnvelope tempRasterBounds = CRS.transform(finalWorldToGridCorner, targetBBox); rasterBounds = tempRasterBounds.toRectangle2D().getBounds(); // SG using the above may lead to problems since the reason is that may be a little (1 px) // bigger // than what we need. The code below is a bit better since it uses a proper logic (see // GridEnvelope // Javadoc) // rasterBounds = new GridEnvelope2D(new Envelope2D(tempRasterBounds), // PixelInCell.CELL_CORNER); if (rasterBounds.width == 0) { rasterBounds.width++; } if (rasterBounds.height == 0) { rasterBounds.height++; } if (oversampledRequest) { rasterBounds.grow(2, 2); } }
/** * Return a crop region from a specified envelope, leveraging on the grid to world * transformation. * * @param refinedRequestedBBox the crop envelope * @return a {@code Rectangle} representing the crop region. * @throws TransformException in case a problem occurs when going back to raster space. */ private Rectangle getCropRegion() throws TransformException { final MathTransform gridToWorldTransform = getOriginalGridToWorld(PixelInCell.CELL_CORNER); final MathTransform worldToGridTransform = gridToWorldTransform.inverse(); final GeneralEnvelope rasterArea = CRS.transform(worldToGridTransform, requestedBBox); final Rectangle2D ordinates = rasterArea.toRectangle2D(); // THIS IS FUNDAMENTAL IN ORDER TO AVOID PROBLEMS WHEN DOING TILING return ordinates.getBounds(); }
CRS.transform(cropWorldToGrid, intersection).toRectangle2D().getBounds();
Shape shape = textLayout.getOutline(rot); Rectangle2D tickLabelBounds = shape.getBounds2D(); if (tickLabelBounds.getBounds().height > maxTickLabelY) { maxTickLabelY = tickLabelBounds.getBounds().height; Rectangle2D tickLabelBounds = shape.getBounds2D(); int tickLabelY = tickLabelBounds.getBounds().height; int yAlignmentOffset; switch (styler.getXAxisLabelAlignmentVertical()) {
CRS.transform(readGridToWorld.inverse(), requestedEnvelopeCropped) .toRectangle2D(); final GeneralGridEnvelope finalRange = new GeneralGridEnvelope(ordinates.getBounds()); final Rectangle tempRect = finalRange.toRectangle();
CRS.transform(cropWorldToGrid, new GeneralEnvelope(intersection)) .toRectangle2D() .getBounds(); XRectangle2D.intersect( sourceArea,
return null; final Rectangle sourceArea = r2d.getBounds();
/** * This method is responsible for computing the raster bounds of the final mosaic. * * @throws TransformException In case transformation fails during the process. */ private void initRasterBounds() throws TransformException { final GeneralEnvelope tempRasterBounds = CRS.transform(finalWorldToGridCorner, mosaicBBox); rasterBounds = tempRasterBounds.toRectangle2D().getBounds(); // SG using the above may lead to problems since the reason is that may be a little (1 px) // bigger // than what we need. The code below is a bit better since it uses a proper logic (see // GridEnvelope // Javadoc) rasterBounds = new GridEnvelope2D(new Envelope2D(tempRasterBounds), PixelInCell.CELL_CORNER); if (rasterBounds.width == 0) rasterBounds.width++; if (rasterBounds.height == 0) rasterBounds.height++; if (oversampledRequest) rasterBounds.grow(2, 2); // make sure the expanded bounds are still within the reach of the granule bounds, not // larger // (the above expansion might have made them so) final GeneralEnvelope levelRasterArea_ = CRS.transform( finalWorldToGridCorner, request.spatialRequestHelper.getCoverageBBox()); final GridEnvelope2D levelRasterArea = new GridEnvelope2D(new Envelope2D(levelRasterArea_), PixelInCell.CELL_CORNER); XRectangle2D.intersect(levelRasterArea, rasterBounds, rasterBounds); }
rasterSpaceEnvelope = CRS.transform(mt, targetEnvelope).toRectangle2D().getBounds(); GridEnvelope2D gridRange = new GridEnvelope2D(rasterSpaceEnvelope); GridGeometry2D gridGeometry = new GridGeometry2D(gridRange, targetEnvelope);
XAffineTransform.transform( sourceWorldToGridTransform, cropEnvelope.toRectangle2D(), null); final Rectangle finalRasterArea = finalRasterAreaDouble.getBounds(); final Rectangle bounds = rasterSpaceROI.getBounds2D().getBounds(); Rectangle.intersect(bounds, sourceGridRange, bounds); if (bounds.isEmpty())
if (imageROI.contains(footprint.getBounds2D().getBounds())) { imageROI = footprint; } else {
@Override public void addNotify() { super.addNotify(); Dimension textSize = getGraphics().getFontMetrics().getStringBounds("100%", getGraphics()).getBounds().getSize(); Dimension minSize = new Dimension(textSize.width, textSize.height + getInsetHeight()); setPreferredSize(minSize); validate(); }
CRS.transform(g2w.inverse(), inputGG.getEnvelope()); Rectangle rect = transformed.toRectangle2D().getBounds();