final jLabel descLabel = new jLabel();
des.setWordWrap(true);
des.setWidth("200px");
descLabel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
tableDisplay.setWidget(row, 2, des);
I'm placing the label inside a FlexTable
This is how it looks in the label. It's exceeding beyond the width I have given for the label.
Appears odd. I mean to say that the long text without whitespace is not following the width I have given for the label. Tried giving this:
public class Jlabel extends Label{
public Jlabel () {
DOM.setStyleAttribute(this.getElement(), "word-wrap", "break-word");
}
wwwwwwwwwr ttttttttttt rrrrrrrrrrrrrrrrr yyyyyyyyyyyyyyyyr rriuoeggn ryyyyyy ryj klrtp;irptiml;rtkroitlrktrpotilr;gkawpeti;lrkgwptjkrotkw;'rtoi4p[tok
Browsers can only break words on whitespace characters. So you need to provide some in your long word.
One option is to insert every 10 characters. This will (should) not display if the word fits into a line.
Related
I am trying to get text value in TMPro Text component without markup tags but haven't found any solutions.
Say, <b><color=red>Hello </color><b> world is the value in TMPro Text, and I just want Hello world in c# script.
Bear in mind that tag <b> and color will change, so I would love to remove tags dynamically, meaning I would like not to replacing each tag by text.replace("<b>", "") kind of things.
Does anyone know how to do it?
I dont know about the option of using HTML on tmp but you can attach the text to your script by create a new variable like that:
[SerializeField] TMP_Text textVar;
then you can drag you tmp game object to the component that include this script
and the you can change the text like that:
textVar.text = "what ever";
or get text like that:
string textString = textVar.text;
for the color you can use
Color color = textVar.color;
You can use TMP_Text.GetParsedText () to get the text after it has been parsed and rich text tags removed.
Alternatively you can also use regular expressions to search a string for rich text tags, and remove them while preserving the rest of the string.
using System.Text.RegularExpressions;
public static string GetString (string str)
{
Regex rich = new Regex (#"<[^>]*>");
if (rich.IsMatch (str))
{
str = rich.Replace (str, string.Empty);
}
return str;
}
I want to implement text wrapping in heading titles.I also have group by layer added on top column header layer
Text wrapping is not working in group by header region with below configuration.How to implement text wrapping in this scenario
// Column header layer
this.colGrpModel = new ColumnGroupModel();
this.colHeaderLayr =
new ColumnHeaderLayer(this.colHeaderDataLayr, this.bodyLayr, this.bodyLayr.getSelectionLayer());
this.colGrpHeaderLayer =
new ColumnGroupHeaderLayer(this.colHeaderLayr,
this.bodyLayr.getSelectionLayer(), this.colGrpModel, false);
this.colGrpHeaderLayer.setCalculateHeight(true);
// Composite layer
CompositeLayer compositeGridLayer = new CompositeLayer(1, 2);
//Group by header layer
this.groupByHeaderLayer = new GroupByHeaderLayer(groupByModel, this.paramFilterGridLayer,
this.filterGridLayer.getColumnHeaderDataProvider());
compositeGridLayer.setChildLayer(GroupByHeaderLayer.GROUP_BY_REGION, this.groupByHeaderLayer, 0, 0);
compositeGridLayer.setChildLayer("Grid", this.filterGridLayer, 0, 1);
This is the groupBy configuration:
configRegstry.registerConfigAttribute(
GroupByConfigAttributes.GROUP_BY_CHILD_COUNT_PATTERN, "[{0}] - ({1})");
configRegstry.registerConfigAttribute(
GroupByConfigAttributes.GROUP_BY_HINT, "Drag columns here");
// To implement text wrapping in group by header region
configRegstry.registerConfigAttribute(
CellConfigAttributes.CELL_PAINTER,
new TextPainter(true, true, 2),
DisplayMode.NORMAL,
GroupByHeaderLayer.GROUP_BY_REGION);
Short answer: This is currently not supported.
Long answer:
You are misunderstanding several things.
Text wrapping means that a new line is added dynamically if there is not enough space in a cell. Since the GroupByHeader is actually one cell that spans the whole width, the cell width will never exceed to force text wrapping.
The TextPainter is a ICellPainter, so it is used to render cells.
The GroupByHeader (although a spanned cell) does not use the default cell painter. It uses the special GroupByHeaderPainter as it needs to inspect the GroupByModeland render fragments for each entry. That painter does currently not support line wrapping. And it does not use other ICellPainter internally.
That means, if you need to support line wrapping in the GroupByHeader you need to extend the GroupByHeaderPainter. As an open source project we like contributions. :)
If you want to add some sort of text wrapping in the GroupByHeader, you somehow need to specify when a text should be wrapped.
I am attempting to use TextMarginFinder to prove that odd and even pages back up correctly when printing. I have based my code on:
http://itextpdf.com/examples/iia.php?id=280
The issue I have is that on odd pages I am looking for the box to be aligned to the left showing a 1CM back margin for example, and on an even page I would expect the page box to be aligned to the right also showing a 1CM back margin. Even in the example above this is not the case, but when printed the text does back up perfectly because the Trim Box conforms.
In summary I believe on certain PDF files the TextMarginFinder is incorrectly locating the text width, usually on Even pages. This is evident by the width being greater than the actual text. This is usually the case if there are slug marks outside of the Media Box area.
In the PDF the OP pointed to (margins.pdf from the iText samples themselves) indeed the box is not flush with the text:
If you look into the PDF Content, though, you'll see that many of the lines have a trailing space character, e.g. the first line:
(s I have worn out since I started my ) Tj
These trailing space characters are part of the text and, therefore, the box does not flush with the visible text but it does with the text including such space characters.
If you want to ignore such space characters, you can try doing so by filtering such trailing spaces (or for the sake of simplicity all spaces) before they get fed into the TextMarginFinder. To do this I'd explode the TextRenderInfo instances character-wise and then filter those which trim to empty strings.
A helper class to explode the render info objects:
import com.itextpdf.text.pdf.parser.ImageRenderInfo;
import com.itextpdf.text.pdf.parser.RenderListener;
import com.itextpdf.text.pdf.parser.TextRenderInfo;
public class TextRenderInfoSplitter implements RenderListener
{
public TextRenderInfoSplitter(RenderListener strategy) {
this.strategy = strategy;
}
public void renderText(TextRenderInfo renderInfo) {
for (TextRenderInfo info : renderInfo.getCharacterRenderInfos()) {
strategy.renderText(info);
}
}
public void beginTextBlock() {
strategy.beginTextBlock();
}
public void endTextBlock() {
strategy.endTextBlock();
}
public void renderImage(ImageRenderInfo renderInfo) {
strategy.renderImage(renderInfo);
}
final RenderListener strategy;
}
Using this helper you can update the iText sample like this:
RenderFilter spaceFilter = new RenderFilter() {
public boolean allowText(TextRenderInfo renderInfo) {
return renderInfo != null && renderInfo.getText().trim().length() > 0;
}
};
PdfReader reader = new PdfReader(src);
PdfReaderContentParser parser = new PdfReaderContentParser(reader);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT));
for (int i = 1; i <= reader.getNumberOfPages(); i++) {
TextMarginFinder finder = new TextMarginFinder();
FilteredRenderListener filtered = new FilteredRenderListener(finder, spaceFilter);
parser.processContent(i, new TextRenderInfoSplitter(filtered));
PdfContentByte cb = stamper.getOverContent(i);
cb.rectangle(finder.getLlx(), finder.getLly(), finder.getWidth(), finder.getHeight());
cb.stroke();
}
stamper.close();
reader.close();
The result:
In case of slug area text etc you might want to filter more, e.g. anything outside the crop box.
Beware, though, there might be fonts in which the space character is not invisible, e.g. a font of boxed characters. Taking the spaces out of the equation in that case would be wrong.
I have TitledPanes which contain large amounts of text. The TitledPanes are put inside of a VBox to lay them out vertically. But, when placed in a VBox, the TitlePane's width becomes the full width of the text instead of wrapping the text. How do I make it so that TitlePane's width is that of the available area, wrapping it's content, if necessary?
In this example, the text wrapping works as intended, but there's no VBox, so you can't have more than one TitledPane.
package nimrandsLibrary.fantasyCraft.characterBuilder
import javafx.scene.control._
import javafx.scene.layout._
import javafx.scene._
class TiltedTextExample extends javafx.application.Application {
def start(stage : javafx.stage.Stage) {
val titledPane = new TitledPane()
titledPane.setText("Expand me!")
val label = new Label("Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here.")
label.setWrapText(true)
titledPane.setContent(label)
stage.setScene(new Scene(titledPane, 300, 300))
stage.show()
}
}
object TiltedTextExample extends App {
javafx.application.Application.launch(classOf[TiltedTextExample])
}
In this example, the TitledPane is placed inside a VBox so that multiple TitlePanes can be added and stacked vertically. Inexplicably, this breaks the word wrapping behavior.
package nimrandsLibrary.fantasyCraft.characterBuilder
import javafx.scene.control._
import javafx.scene.layout._
import javafx.scene._
class TiltedTextExample extends javafx.application.Application {
def start(stage : javafx.stage.Stage) {
val titledPane = new TitledPane()
titledPane.setText("Expand me!")
val label = new Label("Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here.")
label.setWrapText(true)
titledPane.setContent(label)
val vBox = new VBox()
vBox.getChildren().add(titledPane)
stage.setScene(new Scene(vBox, 300, 300))
stage.show()
}
}
object TiltedTextExample extends App {
javafx.application.Application.launch(classOf[TiltedTextExample])
}
I have to delve deep (looking through the JavaFX code itself), but I found a workable, but not ideal, solution.
The problem basically boiled down to the fact that the TitledPane was not coded to support a horizontal content bias (where its min/preferred height is calculated based on its available width). So, even though its content, the Label, supports this functionality, its rendered mote by the TitledPane, which calculates its minimum and preferred dimensions without the consideration of the other, in which case the Label control simply requests a width and height necessary to display all its text on one line.
To overrride this behavior, I had to override three functions, two in the TitledPane itself, and one in the TitlePane's default skin (which actually does the dimension calculations for TitledPane). First, I override the getContentBias return HORIZONTAL. Then, I override the getMinWidth to return 0. Finally, I update the skin's computePrefHeight function to take into account the available width when its asking its children how much height they need.
Here is the code:
package nimrandsLibrary.fantasyCraft.characterBuilder
import javafx.scene.control._
import javafx.scene.layout._
import javafx.scene._
class TiltedTextExample extends javafx.application.Application {
private def createTitledPane(title: String) = {
val titledPane = new HorizontalContentBiasTitledPane()
titledPane.setText(title)
val label = new Label("Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here.")
label.setWrapText(true)
titledPane.setContent(label)
titledPane.setExpanded(false)
titledPane
}
def start(stage: javafx.stage.Stage) {
val vBox = new VBox()
vBox.getChildren().add(createTitledPane("Expand Me #1"))
vBox.getChildren().add(createTitledPane("Expand Me #2"))
vBox.getChildren().add(createTitledPane("Expand Me #3"))
stage.setScene(new Scene(vBox, 300, 300))
stage.show()
}
}
object TiltedTextExample extends App {
javafx.application.Application.launch(classOf[TiltedTextExample])
}
class HorizontalContentBiasTitledPane extends javafx.scene.control.TitledPane {
override def getContentBias() = javafx.geometry.Orientation.HORIZONTAL
override def computeMinWidth(height: Double) = 0
this.setSkin(new com.sun.javafx.scene.control.skin.TitledPaneSkin(this) {
private val getTransitionMethod = classOf[com.sun.javafx.scene.control.skin.TitledPaneSkin].getDeclaredMethod("getTransition")
getTransitionMethod.setAccessible(true)
override protected def computePrefHeight(width: Double) = {
val contentContainer = getChildren().get(0)
val titleRegion = getChildren().get(1)
val headerHeight = Math.max(com.sun.javafx.scene.control.skin.TitledPaneSkin.MIN_HEADER_HEIGHT, snapSize(titleRegion.prefHeight(-1)));
var contentHeight = 0.0;
if (getSkinnable().getParent() != null && getSkinnable().getParent().isInstanceOf[com.sun.javafx.scene.control.skin.AccordionSkin]) {
contentHeight = contentContainer.prefHeight(width);
} else {
contentHeight = contentContainer.prefHeight(width) * getTransitionMethod.invoke(this).asInstanceOf[java.lang.Double].toDouble
}
headerHeight + snapSize(contentHeight) + snapSpace(getInsets().getTop()) + snapSpace(getInsets().getBottom());
}
})
}
This works for my use case, but there are some limitations, some of which can be worked around, and some that cannot.
This code is brittle, as it depends on specific implementation details of Java FX, especially the part where I have to call a private method on TitlePane's default skin. I don't see any easy way to fix this, other than to re-implement TitlePane's default skin in its enteritety (which I guess isn't too difficult, since the code is available).
Clamping the minWidth of the TitlePane to 0 it potentially problematic. A more robust algorithm might be necessary, depending on the use case.
Similarly, hard-coding title pane's content bias to HORIZONTAL isn't ideal. A more robust solution would be to use the content bias of its content, and make the dimension calculations of the control work based on that content bias.
Despite the limitations, this code seems to work for me, and I think the modifications to make it more robust are fairly straightforward. However, if anyone has a less drastic solution, or can improve on mine, please contribute.
Use Text instead of label. Example is as below,
#Override
public void start(Stage primaryStage) {
StackPane root = new StackPane();
primaryStage.setScene(new Scene(root, 300, 250));
primaryStage.setTitle("Hello World!");
VBox vBox = new VBox();
TitledPane tPane = new TitledPane();
tPane.setText("expand me");
tPane.setPrefWidth(root.getWidth());
Text text = new Text();
text.setText("Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here. Some really long text here.");
text.setWrappingWidth(tPane.getPrefWidth());
tPane.setContent(text);
vBox.getChildren().add(tPane);
root.getChildren().add(vBox);
primaryStage.show();
}
The titlepane of javafx will take the maximum width of its children.
Result:
Using iTextSharp i'm trying to align an image so that it gets embedded in a paragraph. I can do it like this:
iTextSharp.text.Image image;
image.Alignment = Image.ALIGN_RIGHT | Image.TEXTWRAP;
document.Add(image);
document.Add(new Paragraph("Large string of text goes here"));
But the image comes out on the top right with the text surrounding it (kind of like an L)
What I want is the text to be a few paragraphs then the image with text below it (kind of like a C). Does anyone know how I would do this VIA iTextSharp?
Edit:
I also tried
iTextSharp.text.Image image;
image.Alignment = Image.ALIGN_RIGHT | Image.TEXTWRAP | Image.ALIGN_MIDDLE;
document.Add(image);
document.Add(new Paragraph("Large string of text goes here"));
But it was displayed with the image at the top and the text below it. There was no textwrap in effect.
The Phrase and the Paragraph objects do behave differently. Try changing to:
image.Alignment = 6;
document.Add(image);
document.Add(new Phrase("Large string of text goes here"));
This worked for me in VB. ( I had to change the image alignment to the sum of the integer values for ALIGN_RIGHT and TEXTWRAP to get this to work properly).
ALIGN_RIGHT = 2
TEXTWRAP = 4
Your image was displayed at the top of the page because it was the first thing added to the document, and the text was added after it.
You can move the image down by either setting its absolute position, or by adding some of your text to the document, then adding the image, then adding the rest of your text.
The easiest way to embed image into paragraph is to use InlineImage from PDFFlow library.
InlineImage was created exactly for this purpose.
Example of adding an inline image with margins:
var imagePath = "imageFile.png";
DocumentBuilder.New()
.AddSection()
.AddParagraph()
.AddTextToParagraph("Inline image")
.AddInlineImage(imagePath, new XSize(16, 16), ScalingMode.UserDefined)
.SetMarginLeft(8)
.SetMarginRight(8)
.ToParagraph()
.AddText("in paragraph.")
.ToDocument()
.Build("Result.pdf");
The above code will generate the following:
Here are business documents examples with source code: Examples.
Hope, this will help.