में फ़ॉन्ट आकार (और छवि आकार) को ज़ूम/स्केल करना संभव है क्या यह किसी भी तरह जेडॉम टेक्स्ट और जेडडिटरपेन में चित्रों के लिए संभव है।जेडडिटरपेन
मुझे फ़ॉन्ट आकार बड़ा बनाने के लिए सभी HTML पृष्ठों से गुजरना पसंद नहीं है।
में फ़ॉन्ट आकार (और छवि आकार) को ज़ूम/स्केल करना संभव है क्या यह किसी भी तरह जेडॉम टेक्स्ट और जेडडिटरपेन में चित्रों के लिए संभव है।जेडडिटरपेन
मुझे फ़ॉन्ट आकार बड़ा बनाने के लिए सभी HTML पृष्ठों से गुजरना पसंद नहीं है।
JEditorPane इस का समर्थन नहीं करता है, लेकिन आप एक छोटे से कार्यक्षमता की जरूरत को जोड़ने के लिए विस्तार कर सकते हैं ...
इस प्रयास करें:
बाहर चेक TransformUI है, जो एक है JXLayer का ठंडा "एक्सटेंशन"। demo शुरू करें, और अपना जबड़ा ड्रॉप करें! ;-) ('ऑटो पैक' चेक बॉक्स दबाएं)
असल में, यह क्या करता है, घटक पर पेंट का आविष्कार करने से पहले एक स्केलिंग एफ़िनट्रांसफॉर्म सेट करना है, इस प्रकार घटक को सबकुछ बढ़ाया जाता है। इस प्रकार, आपका ज़ूम ठीक है ..!
मैं अपने कस्टमाइज़्ड HTMLEditorKit कर दिया कि/बाहर एक JEditorPane की HTML सामग्री में ज़ूम कर सकते हैं, तो यह और भी बेहतर ढंग से प्रतिपादन प्रदर्शन है, मैं इसे LargeHTMLEditorKit कहा जाता है:
/**
* An extended {@link HTMLEditorKit} that allow faster
* rendering of large html files and allow zooming of content.
* @author Alessio Pollero
* @version 1.0
*/
public class LargeHTMLEditorKit extends HTMLEditorKit {
ViewFactory factory = new MyViewFactory();
@Override
public ViewFactory getViewFactory() {
return factory;
}
class MyViewFactory extends HTMLFactory {
@Override
public View create(Element elem) {
AttributeSet attrs = elem.getAttributes();
Object elementName = attrs.getAttribute(AbstractDocument.ElementNameAttribute);
Object o = (elementName != null) ? null : attrs.getAttribute(StyleConstants.NameAttribute);
if (o instanceof HTML.Tag) {
HTML.Tag kind = (HTML.Tag) o;
if (kind == HTML.Tag.HTML) {
return new HTMLBlockView(elem);
}
else if (kind == HTML.Tag.IMPLIED) {
String ws = (String) elem.getAttributes().getAttribute(CSS.Attribute.WHITE_SPACE);
if ((ws != null) && ws.equals("pre")) {
return super.create(elem);
}
return new HTMLParagraphView(elem);
} else if ((kind == HTML.Tag.P) ||
(kind == HTML.Tag.H1) ||
(kind == HTML.Tag.H2) ||
(kind == HTML.Tag.H3) ||
(kind == HTML.Tag.H4) ||
(kind == HTML.Tag.H5) ||
(kind == HTML.Tag.H6) ||
(kind == HTML.Tag.DT)) {
// paragraph
return new HTMLParagraphView(elem);
}
}
return super.create(elem);
}
}
private class HTMLBlockView extends BlockView {
public HTMLBlockView(Element elem) {
super(elem, View.Y_AXIS);
}
@Override
protected void layout(int width, int height) {
if (width<Integer.MAX_VALUE) {
super.layout(new Double(width/getZoomFactor()).intValue(),
new Double(height *
getZoomFactor()).intValue());
}
}
public double getZoomFactor() {
Double scale = (Double) getDocument().getProperty("ZOOM_FACTOR");
if (scale != null) {
return scale.doubleValue();
}
return 1;
}
@Override
public void paint(Graphics g, Shape allocation) {
Graphics2D g2d = (Graphics2D) g;
double zoomFactor = getZoomFactor();
AffineTransform old = g2d.getTransform();
g2d.scale(zoomFactor, zoomFactor);
super.paint(g2d, allocation);
g2d.setTransform(old);
}
@Override
public float getMinimumSpan(int axis) {
float f = super.getMinimumSpan(axis);
f *= getZoomFactor();
return f;
}
@Override
public float getMaximumSpan(int axis) {
float f = super.getMaximumSpan(axis);
f *= getZoomFactor();
return f;
}
@Override
public float getPreferredSpan(int axis) {
float f = super.getPreferredSpan(axis);
f *= getZoomFactor();
return f;
}
@Override
public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException {
double zoomFactor = getZoomFactor();
Rectangle alloc;
alloc = a.getBounds();
Shape s = super.modelToView(pos, alloc, b);
alloc = s.getBounds();
alloc.x *= zoomFactor;
alloc.y *= zoomFactor;
alloc.width *= zoomFactor;
alloc.height *= zoomFactor;
return alloc;
}
@Override
public int viewToModel(float x, float y, Shape a,
Position.Bias[] bias) {
double zoomFactor = getZoomFactor();
Rectangle alloc = a.getBounds();
x /= zoomFactor;
y /= zoomFactor;
alloc.x /= zoomFactor;
alloc.y /= zoomFactor;
alloc.width /= zoomFactor;
alloc.height /= zoomFactor;
return super.viewToModel(x, y, alloc, bias);
}
}
}
और यहाँ आवश्यक है HTMLParagraphView:
class HTMLParagraphView extends ParagraphView {
public static int MAX_VIEW_SIZE=100;
public HTMLParagraphView(Element elem) {
super(elem);
strategy = new HTMLParagraphView.HTMLFlowStrategy();
}
public static class HTMLFlowStrategy extends FlowStrategy {
protected View createView(FlowView fv, int startOffset, int spanLeft, int rowIndex) {
View res=super.createView(fv, startOffset, spanLeft, rowIndex);
if (res.getEndOffset()-res.getStartOffset()> MAX_VIEW_SIZE) {
res = res.createFragment(startOffset, startOffset+ MAX_VIEW_SIZE);
}
return res;
}
}
public int getResizeWeight(int axis) {
return 0;
}
}
तो फिर तुम यह इस तरह से उपयोग कर सकते हैं:
//Create a new JEditorPane
JEditorPane yourPane = new JEditorPane();
//Set the custom HTMLEditorKit
yourPane.setEditorKit(new LargeHTMLEditorKit());
//Set the zoom to 150%
yourPane.getDocument().putProperty("ZOOM_FACTOR", new Double(1.5));
धन्यवाद, दुर्भाग्यवश यह मेरे HTMLEditorKit के साथ काम नहीं कर रहा है, टेक्स्ट आकार कोई बड़ा नहीं है। – Tom
आपको इसे HTMLEditorKit के लिए कस्टमाइज़ करने की आवश्यकता होगी, यह ट्यूटोरियल एक ही चीज़ करता है लेकिन स्टाइल एडिटरकिट के लिए। – stephendl
मैं इसे करने में सक्षम नहीं था, क्लास स्टाइलव्यूफैक्टरी लागू करता है ViewFactory ने HTML का समर्थन नहीं किया है, यह लेबलव्यू पर डिफ़ॉल्ट है जिससे कई समस्याएं आती हैं। – Tom