List of usage examples for com.google.gwt.dom.client Style clearFontSize
public void clearFontSize()
From source file:com.sciencegadgets.client.ui.FitParentHTML.java
License:Open Source License
private double getFontPercent() { if (this.getParent() == null) { return 100; }/*w w w .j a v a 2 s. c o m*/ Element htmlElement = this.getElement(); Style htmlStyle = htmlElement.getStyle(); htmlStyle.clearPadding(); htmlStyle.clearFontSize(); Element parentElement = this.getParent().getElement(); double widthRatio = (double) parentElement.getOffsetWidth() / (double) htmlElement.getOffsetWidth(); double heightRatio = (double) parentElement.getOffsetHeight() / (double) htmlElement.getOffsetHeight(); double smallerRatio = (widthRatio > heightRatio) ? heightRatio : widthRatio; // *percentOfParent for looser fit, *100 for percent return smallerRatio * percentOfParent; }
From source file:com.sencha.gxt.chart.client.draw.engine.VML.java
License:sencha.com license
/** * Applies the attributes of the passed {@link TextSprite} to its VML element. * /*from w w w . j ava 2 s . c om*/ * @param sprite the sprite whose attributes to use */ private void setTextAttributes(TextSprite sprite, XElement element) { Element textPath = element.childElement("textPath").cast(); Style textStyle = textPath.getStyle(); textBBoxCache.remove(sprite); if (sprite.isFontSizeDirty() || ignoreOptimizations) { if (sprite.getFontSize() > 0) { textStyle.setFontSize(sprite.getFontSize(), Unit.PX); } else { textStyle.clearFontSize(); } } if (sprite.isFontStyleDirty() || ignoreOptimizations) { if (sprite.getFontStyle() != null) { textStyle.setFontStyle(sprite.getFontStyle()); } else { textStyle.clearFontStyle(); } } if (sprite.isFontWeightDirty() || ignoreOptimizations) { if (sprite.getFontWeight() != null) { textStyle.setFontWeight(sprite.getFontWeight()); } else { textStyle.clearFontWeight(); } } if (sprite.isFontDirty() || ignoreOptimizations) { if (sprite.getFont() != null) { textStyle.setProperty("fontFamily", sprite.getFont()); } else { textStyle.clearProperty("fontFamily"); } } // text-anchor emulation if (sprite.isTextAnchorDirty() || ignoreOptimizations) { if (sprite.getTextAnchor() == TextAnchor.MIDDLE) { setTextAlign(textStyle, "center"); } else if (sprite.getTextAnchor() == TextAnchor.END) { setTextAlign(textStyle, "right"); } else { setTextAlign(textStyle, "left"); } } if (sprite.isTextDirty() || ignoreOptimizations) { if (sprite.getText() != null) { textPath.setPropertyString("string", sprite.getText()); } else { textPath.setPropertyString("string", ""); } } if (sprite.isTextBaselineDirty() || sprite.isXDirty() || sprite.isYDirty() || ignoreOptimizations) { double height = sprite.getFontSize(); if (sprite.getTextBaseline() == TextBaseline.MIDDLE) { height = 0; } else if (sprite.getTextBaseline() == TextBaseline.BOTTOM) { height *= -1; } Element path = element.childElement("path").cast(); path.setPropertyString("v", new StringBuilder().append("m").append(Math.round(sprite.getX() * zoom)).append(",") .append(Math.round((sprite.getY() + (height / 2.0)) * zoom)).append(" l") .append(Math.round(sprite.getX() * zoom) + 1).append(",") .append(Math.round((sprite.getY() + (height / 2.0)) * zoom)).toString()); textRenderedPoints.put(sprite, new PrecisePoint(sprite.getX(), sprite.getY())); textRenderedBaseline.put(sprite, sprite.getTextBaseline()); } }
From source file:org.waveprotocol.wave.client.editor.content.paragraph.DefaultParagraphHtmlRenderer.java
License:Apache License
@Override public void updateRendering(HasImplNodelets element, String type, String listStyle, int indent, Alignment alignment, Direction direction) { Element implNodelet = element.getImplNodelet(); ParagraphBehaviour behaviour = ParagraphBehaviour.of(type); boolean toListItem = behaviour == ParagraphBehaviour.LIST; boolean isListItem = implNodelet.getTagName().equalsIgnoreCase(LIST_IMPL_TAGNAME); if (isListItem != toListItem) { Element newNodelet = createNodeletInner(toListItem); DomHelper.replaceElement(implNodelet, newNodelet); element.setBothNodelets(newNodelet); // Ideally onRepair shouldn't require a ContentElement ParagraphHelper.INSTANCE.onRepair((ContentElement) element); implNodelet = newNodelet;/*from ww w. j ava 2 s . c o m*/ } //// Type logic //// double fontSize = -1; FontWeight fontWeight = null; implNodelet.removeClassName(NUMBERED_CLASSNAME); switch (behaviour) { case LIST: if (Paragraph.LIST_STYLE_DECIMAL.equals(listStyle)) { implNodelet.addClassName(NUMBERED_CLASSNAME); } break; case HEADING: fontWeight = FontWeight.BOLD; double headingNum = Integer.parseInt(type.substring(1)); // Do this with CSS instead. // h1 -> 1.75, h4 -> 1, others linearly in between. double factor = 1 - (headingNum - 1) / (Paragraph.NUM_HEADING_SIZES - 1); fontSize = MIN_HEADING_SIZE_EM + factor * (MAX_HEADING_SIZE_EM - MIN_HEADING_SIZE_EM); break; } //// Indent logic //// for (String bulletType : BULLET_CLASSNAMES) { implNodelet.removeClassName(bulletType); } if (behaviour == ParagraphBehaviour.LIST) { if (listStyle == null) { implNodelet.addClassName(bulletClassName(indent)); } indent++; } int margin = indent * INDENT_UNIT_SIZE_PX; //// Update actual values //// // NOTE(danilatos): For these, it might be more efficient to check that the // value has changed before changing it. This is not currently known. Style style = implNodelet.getStyle(); if (fontSize != -1) { style.setFontSize(fontSize, Unit.EM); } else { style.clearFontSize(); } if (fontWeight != null) { style.setFontWeight(fontWeight); } else { style.clearFontWeight(); } if (alignment != null) { style.setProperty("textAlign", alignment.cssValue()); } else { style.clearProperty("textAlign"); } if (direction != null) { style.setProperty("direction", direction.cssValue()); } else { style.clearProperty("direction"); } if (margin == 0) { style.clearMarginLeft(); style.clearMarginRight(); } else { if (direction == Direction.RTL) { style.setMarginRight(margin, Unit.PX); style.clearMarginLeft(); } else { style.setMarginLeft(margin, Unit.PX); style.clearMarginRight(); } } }