Skip to content

Commit

Permalink
For #23 - Clean up SVG user agent by using adapter rather than interf…
Browse files Browse the repository at this point in the history
…ace.
  • Loading branch information
danfickle committed Feb 13, 2017
1 parent 330597d commit eaf1129
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 245 deletions.
Original file line number Diff line number Diff line change
@@ -1,260 +1,19 @@
package com.openhtmltopdf.svgsupport;

import java.awt.Cursor;
import java.awt.Point;
import java.awt.geom.AffineTransform;
import java.awt.geom.Dimension2D;

import org.apache.batik.bridge.BridgeExtension;
import org.apache.batik.bridge.ExternalResourceSecurity;
import org.apache.batik.bridge.FontFamilyResolver;
import org.apache.batik.bridge.Mark;
import org.apache.batik.bridge.ScriptSecurity;
import org.apache.batik.bridge.UserAgent;
import org.apache.batik.gvt.event.EventDispatcher;
import org.apache.batik.util.ParsedURL;
import org.w3c.dom.Element;
import org.w3c.dom.svg.SVGAElement;
import org.w3c.dom.svg.SVGDocument;

import org.apache.batik.bridge.UserAgentAdapter;
import com.openhtmltopdf.svgsupport.PDFTranscoder.OpenHtmlFontResolver;

public class OpenHtmlUserAgent implements UserAgent {
public class OpenHtmlUserAgent extends UserAgentAdapter {

private final OpenHtmlFontResolver resolver;

public OpenHtmlUserAgent(OpenHtmlFontResolver resolver) {
this.resolver = resolver;
}

@Override
public boolean supportExtension(String arg0) {
// TODO Auto-generated method stub
return false;
}

@Override
public String showPrompt(String arg0, String arg1) {
// TODO Auto-generated method stub
return null;
}

@Override
public String showPrompt(String arg0) {
// TODO Auto-generated method stub
return null;
}

@Override
public boolean showConfirm(String arg0) {
// TODO Auto-generated method stub
return false;
}

@Override
public void showAlert(String arg0) {
// TODO Auto-generated method stub

}

@Override
public void setTransform(AffineTransform arg0) {
// TODO Auto-generated method stub

}

@Override
public void setTextSelection(Mark arg0, Mark arg1) {
// TODO Auto-generated method stub

}

@Override
public void setSVGCursor(Cursor arg0) {
// TODO Auto-generated method stub

}

@Override
public void registerExtension(BridgeExtension arg0) {
// TODO Auto-generated method stub

}

@Override
public void openLink(SVGAElement arg0) {
// TODO Auto-generated method stub

}

@Override
public void loadDocument(String arg0) {
System.err.println("LOAD DOC: " + arg0);

}

@Override
public boolean isXMLParserValidating() {
// TODO Auto-generated method stub
return false;
}

@Override
public boolean hasFeature(String arg0) {
// TODO Auto-generated method stub
return false;
}

@Override
public void handleElement(Element arg0, Object arg1) {
// TODO Auto-generated method stub

}

@Override
public String getXMLParserClassName() {
// TODO Auto-generated method stub
return null;
}

@Override
public Dimension2D getViewportSize() {
// TODO Auto-generated method stub
return null;
}

@Override
public String getUserStyleSheetURI() {
// TODO Auto-generated method stub
return null;
}

@Override
public AffineTransform getTransform() {
// TODO Auto-generated method stub
return null;
}

@Override
public ScriptSecurity getScriptSecurity(String arg0, ParsedURL arg1,
ParsedURL arg2) {
// TODO Auto-generated method stub
return null;
}

@Override
public float getPixelUnitToMillimeter() {
// TODO Auto-generated method stub
return 0;
}

@Override
public float getPixelToMM() {
// TODO Auto-generated method stub
return 0;
}

@Override
public float getMediumFontSize() {
// TODO Auto-generated method stub
return 0;
}

@Override
public String getMedia() {
return "print";
}

@Override
public float getLighterFontWeight(float arg0) {
// TODO Auto-generated method stub
return 0;
}

@Override
public String getLanguages() {
// TODO Auto-generated method stub
return null;
}


@Override
public FontFamilyResolver getFontFamilyResolver() {
return this.resolver;
}

@Override
public ExternalResourceSecurity getExternalResourceSecurity(ParsedURL arg0,
ParsedURL arg1) {
// TODO Auto-generated method stub
return null;
}

@Override
public EventDispatcher getEventDispatcher() {
// TODO Auto-generated method stub
return null;
}

@Override
public String getDefaultFontFamily() {
// TODO Auto-generated method stub
return null;
}

@Override
public Point getClientAreaLocationOnScreen() {
// TODO Auto-generated method stub
return null;
}

@Override
public SVGDocument getBrokenLinkDocument(Element arg0, String arg1,
String arg2) {
// TODO Auto-generated method stub
return null;
}

@Override
public float getBolderFontWeight(float arg0) {
// TODO Auto-generated method stub
return 0;
}

@Override
public String getAlternateStyleSheet() {
// TODO Auto-generated method stub
return null;
}

@Override
public void displayMessage(String arg0) {
// TODO Auto-generated method stub

}

@Override
public void displayError(Exception arg0) {
// TODO Auto-generated method stub

}

@Override
public void deselectAll() {
// TODO Auto-generated method stub

}

@Override
public void checkLoadScript(String arg0, ParsedURL arg1, ParsedURL arg2)
throws SecurityException {
// TODO Auto-generated method stub

}

@Override
public void checkLoadExternalResource(ParsedURL arg0, ParsedURL arg1)
throws SecurityException {
// TODO Auto-generated method stub

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ public void importFontFaces(List<FontFaceRule> fontFaces, SharedContext ctx) {

@Override
protected void transcode(Document svg, String uri, TranscoderOutput out) throws TranscoderException {

// Note: We have to initialize user agent here and not in ::createUserAgent() as method
// is called before our constructor is called in the super constructor.
this.userAgent = new OpenHtmlUserAgent(this.fontResolver);
super.transcode(svg, uri, out);

Expand All @@ -204,6 +207,11 @@ public void render(Graphics2D graphics2D) {
});
}

@Override
protected org.apache.batik.bridge.UserAgent createUserAgent() {
return null;
}

@Override
public ErrorHandler getErrorHandler() {
return new ErrorHandler() {
Expand Down

0 comments on commit eaf1129

Please sign in to comment.