// TransformerHandler public void setResult(Result result) throws IllegalArgumentException { Check.notNull(result); if (result instanceof SAXResult) { setTarget((SAXResult) result); } else { TransformerHandler th = saxHelper.newIdentityTransformerHandler(); th.setResult(result); setTarget(new SAXResult(th)); } }
public long transform( BufferedImage src, OutputStream os, @Nullable Integer _targetWidth, @Nullable Integer targetHeigth, String outputFormat, boolean allowDistort) throws IOException, IllegalArgumentException { Integer targetWidth = Check.ifNull(_targetWidth, src.getWidth()); int[] g = clipCalc(src.getWidth(), src.getHeight(), targetWidth, targetHeigth, allowDistort); return transform(src, os, outputFormat, g); }
private void setTarget(SAXResult result) { ContentHandler ch = result.getHandler(); Check.notNull(ch); contentHandler = ch; LexicalHandler lh = result.getLexicalHandler(); if (lh != null) { lexicalHandler = lh; if (lexicalHandler instanceof DTDHandler) { dtdHandler = (DTDHandler) lexicalHandler; } } if (contentHandler instanceof DTDHandler) { dtdHandler = (DTDHandler) contentHandler; } }
/** * @param sw source canvas width * @param sh source canvas height * @param dw dest canvas width * @param dh dest canvas height (nullable) * @param allowDistort * @return six integers that represent P1(0,1) P2(2,3) W(4) H(5) where P1 and P2 are the src * clipping points and W,H are the actual dest width/height */ protected int[] clipCalc( int sw, int sh, int dw, @Nullable Integer dh, boolean allowDistort /*, boolean allowExpand */) { Check.notNull(dw); boolean allowExpand = allowDistort; if (dh == null) { // full return sw < dw ? new int[] {0, 0, sw, sh, sw, sh} : new int[] {0, 0, sw, sh, dw, scale(sh, dw, sw)}; } else if (allowDistort && allowExpand) { return new int[] {0, 0, sw, sh, dw, dh}; } else { // clever scaling if (dw > sw && dh > sh) { return new int[] {0, 0, sw, sh, sw, sh}; } else if (dh > sh) { int margin = approx((double) (sw - dw) / 2); return new int[] {0 + margin, 0, sw - margin, sh, dw, sh}; } else if (dw > sw) { int margin = approx((double) (sh - dh) / 2); return new int[] {0, 0 + margin, sw, sh - margin, sw, dh}; } else { double xRatio = (double) sw / (double) dw; double yRatio = (double) sh / (double) dh; if (xRatio > yRatio) { int margin = approx((double) (sw - scale(dw, sh, dh)) / 2); return new int[] {0 + margin, 0, sw - margin, sh, dw, dh}; } else { int margin = approx((double) (sh - scale(dh, sw, dw)) / 2); return new int[] {0, 0 + margin, sw, sh - margin, dw, dh}; } } } }
public HandlerAndFiltersBean(Object handler, List<HandlerFilter> filters) { this.handler = Check.notNull(handler); this.filters = Collections.unmodifiableList(Check.notNull(filters)); }
public void setSystemId(String systemID) { Check.notNull(systemID); baseURI = URI.create(systemID); Check.illegalargument.assertTrue(baseURI.isAbsolute() || systemID.startsWith("/")); }