< prev index next > modules/javafx.graphics/src/test/java/test/com/sun/javafx/pgstub/StubTextLayout.java
Print this page
/*
! * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
/*
! * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
return true;
}
private String text;
private Font font;
+ private int tabSize = DEFAULT_TAB_SIZE;
+
@Override
public boolean setContent(String text, Object font) {
this.text = text;
final StubFontLoader.StubFont stub = ((StubFontLoader.StubFont)font);
this.font = stub == null ? null : stub.font;
final double fontSize = (font == null ? 0 : ((Font)font).getSize());
final String[] lines = text.split("\n");
double width = 0.0;
double height = fontSize * lines.length;
for (String line : lines) {
! width = Math.max(width, fontSize * line.length());
}
return bounds.deriveWithNewBounds(0, (float)-fontSize, 0,
(float)width, (float)(height-fontSize), 0);
}
final double fontSize = (font == null ? 0 : ((Font)font).getSize());
final String[] lines = text.split("\n");
double width = 0.0;
double height = fontSize * lines.length;
for (String line : lines) {
! int tabs = 0;
+ final int length;
+ if (line.contains("\t")) {
+ // count chars but when encountering a tab round up to a tabSize boundary
+ char [] chrs = line.toCharArray();
+ int spaces = 0;
+ for (int i = 0; i < chrs.length; i++) {
+ if (chrs[i] == '\t') {
+ if (tabSize != 0) {
+ while ((++spaces % tabSize) != 0) {}
+ }
+ } else {
+ spaces++;
+ }
+ }
+ length = spaces;
+ } else {
+ length = line.length();
+ }
+ width = Math.max(width, fontSize * length);
}
return bounds.deriveWithNewBounds(0, (float)-fontSize, 0,
(float)width, (float)(height-fontSize), 0);
}
@Override
public BaseBounds getVisualBounds(int type) {
return new RectBounds();
}
+ @Override
+ public boolean setTabSize(int spaces) {
+ if (spaces < 1)
+ spaces = 1;
+ if (tabSize != spaces) {
+ tabSize = spaces;
+ return true;
+ }
+ return false;
+ }
+
}
< prev index next >