Mercurial > projects > dwt-mac
comparison dwt/custom/StyledText.d @ 154:535243e6d16a
Fixes to make dwt compile with ldc
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Sat, 13 Jun 2009 00:25:05 +0200 |
parents | 1324fd764db4 |
children |
comparison
equal
deleted
inserted
replaced
153:8433dabeb15e | 154:535243e6d16a |
---|---|
542 numberingWidth = Math.max(numberingWidth, lineWidth); | 542 numberingWidth = Math.max(numberingWidth, lineWidth); |
543 } | 543 } |
544 } | 544 } |
545 } else { | 545 } else { |
546 StringBuffer buffer = new StringBuffer("0"); | 546 StringBuffer buffer = new StringBuffer("0"); |
547 while ((count /= 10) > 0) buffer.append("0"); | 547 while ((count /= 10) > 0) buffer.format("{}", "0"); |
548 printLayout.setText(buffer.toString()); | 548 printLayout.setText(buffer.toString()); |
549 numberingWidth = printLayout.getBounds().width; | 549 numberingWidth = printLayout.getBounds().width; |
550 } | 550 } |
551 numberingWidth += printMargin; | 551 numberingWidth += printMargin; |
552 if (numberingWidth > width) numberingWidth = width; | 552 if (numberingWidth > width) numberingWidth = width; |
650 void printDecorationSegment(String segment, int alignment, int page, bool header, TextLayout layout) { | 650 void printDecorationSegment(String segment, int alignment, int page, bool header, TextLayout layout) { |
651 int pageIndex = segment.indexOf(StyledTextPrintOptions.PAGE_TAG); | 651 int pageIndex = segment.indexOf(StyledTextPrintOptions.PAGE_TAG); |
652 if (pageIndex !is -1 ) { | 652 if (pageIndex !is -1 ) { |
653 int pageTagLength = StyledTextPrintOptions.PAGE_TAG.length; | 653 int pageTagLength = StyledTextPrintOptions.PAGE_TAG.length; |
654 StringBuffer buffer = new StringBuffer(segment.substring (0, pageIndex)); | 654 StringBuffer buffer = new StringBuffer(segment.substring (0, pageIndex)); |
655 buffer.append (page); | 655 buffer.format ("{}", page); |
656 buffer.append (segment.substring(pageIndex + pageTagLength)); | 656 buffer.format ("{}", segment.substring(pageIndex + pageTagLength)); |
657 segment = buffer.toString().dup; | 657 segment = buffer.toString().dup; |
658 } | 658 } |
659 if (segment.length > 0) { | 659 if (segment.length > 0) { |
660 layout.setText(segment); | 660 layout.setText(segment); |
661 int segmentWidth = layout.getBounds().width; | 661 int segmentWidth = layout.getBounds().width; |
904 * Writes the RTF header including font table and color table. | 904 * Writes the RTF header including font table and color table. |
905 */ | 905 */ |
906 void writeHeader() { | 906 void writeHeader() { |
907 StringBuffer header = new StringBuffer(); | 907 StringBuffer header = new StringBuffer(); |
908 FontData fontData = getFont().getFontData()[0]; | 908 FontData fontData = getFont().getFontData()[0]; |
909 header.append("{\\rtf1\\ansi"); | 909 header.format("{}", "{\\rtf1\\ansi"); |
910 // specify code page, necessary for copy to work in bidi | 910 // specify code page, necessary for copy to work in bidi |
911 // systems that don't support Unicode RTF. | 911 // systems that don't support Unicode RTF. |
912 // PORTING_TODO: String cpg = System.getProperty("file.encoding").toLowerCase(); | 912 // PORTING_TODO: String cpg = System.getProperty("file.encoding").toLowerCase(); |
913 String cpg = "UTF16"; | 913 String cpg = "UTF16"; |
914 /+ | 914 /+ |
915 if (cpg.startsWith("cp") || cpg.startsWith("ms")) { | 915 if (cpg.startsWith("cp") || cpg.startsWith("ms")) { |
916 cpg = cpg.substring(2, cpg.length()); | 916 cpg = cpg.substring(2, cpg.length()); |
917 header.append("\\ansicpg"); | 917 header.format("{}", "\\ansicpg"); |
918 header.append(cpg); | 918 header.format("{}", cpg); |
919 } | 919 } |
920 +/ | 920 +/ |
921 header.append("\\uc0\\deff0{\\fonttbl{\\f0\\fnil "); | 921 header.format("{}", "\\uc0\\deff0{\\fonttbl{\\f0\\fnil "); |
922 header.append(fontData.getName()); | 922 header.format("{}", fontData.getName()); |
923 header.append(";"); | 923 header.format("{}", ";"); |
924 for (int i = 1; i < fontTable.length; i++) { | 924 for (int i = 1; i < fontTable.length; i++) { |
925 header.append("\\f"); | 925 header.format("{}", "\\f"); |
926 header.append(i); | 926 header.format("{}", i); |
927 header.append(" "); | 927 header.format("{}", " "); |
928 FontData fd = (cast(Font)fontTable[i]).getFontData()[0]; | 928 FontData fd = (cast(Font)fontTable[i]).getFontData()[0]; |
929 header.append(fd.getName()); | 929 header.format("{}", fd.getName()); |
930 header.append(";"); | 930 header.format("{}", ";"); |
931 } | 931 } |
932 header.append("}}\n{\\colortbl"); | 932 header.format("{}", "}}\n{\\colortbl"); |
933 for (int i = 0; i < colorTable.length; i++) { | 933 for (int i = 0; i < colorTable.length; i++) { |
934 Color color = cast(Color) colorTable[i]; | 934 Color color = cast(Color) colorTable[i]; |
935 header.append("\\red"); | 935 header.format("{}", "\\red"); |
936 header.append(color.getRed()); | 936 header.format("{}", color.getRed()); |
937 header.append("\\green"); | 937 header.format("{}", "\\green"); |
938 header.append(color.getGreen()); | 938 header.format("{}", color.getGreen()); |
939 header.append("\\blue"); | 939 header.format("{}", "\\blue"); |
940 header.append(color.getBlue()); | 940 header.format("{}", color.getBlue()); |
941 header.append(";"); | 941 header.format("{}", ";"); |
942 } | 942 } |
943 // some RTF readers ignore the deff0 font tag. Explicitly | 943 // some RTF readers ignore the deff0 font tag. Explicitly |
944 // set the font for the whole document to work around this. | 944 // set the font for the whole document to work around this. |
945 header.append("}\n{\\f0\\fs"); | 945 header.format("{}", "}\n{\\f0\\fs"); |
946 // font size is specified in half points | 946 // font size is specified in half points |
947 header.append(fontData.getHeight() * 2); | 947 header.format("{}", fontData.getHeight() * 2); |
948 header.append(" "); | 948 header.format("{}", " "); |
949 write(header.toString(), 0); | 949 write(header.toString(), 0); |
950 } | 950 } |
951 /** | 951 /** |
952 * Appends the specified line text to the RTF data. Lines will be formatted | 952 * Appends the specified line text to the RTF data. Lines will be formatted |
953 * using the styles queried from the LineStyleListener, if set, or those set | 953 * using the styles queried from the LineStyleListener, if set, or those set |
1207 } | 1207 } |
1208 /** | 1208 /** |
1209 * Appends the given string to the data. | 1209 * Appends the given string to the data. |
1210 */ | 1210 */ |
1211 void write(String string) { | 1211 void write(String string) { |
1212 buffer.append(string); | 1212 buffer.format("{}", string); |
1213 } | 1213 } |
1214 /** | 1214 /** |
1215 * Inserts the given string to the data at the specified offset. | 1215 * Inserts the given string to the data at the specified offset. |
1216 * <p> | 1216 * <p> |
1217 * Do nothing if "offset" is < 0 or > getCharCount() | 1217 * Do nothing if "offset" is < 0 or > getCharCount() |
1229 } | 1229 } |
1230 /** | 1230 /** |
1231 * Appends the given int to the data. | 1231 * Appends the given int to the data. |
1232 */ | 1232 */ |
1233 void write(int i) { | 1233 void write(int i) { |
1234 buffer.append(i); | 1234 buffer.format("{}", i); |
1235 } | 1235 } |
1236 /** | 1236 /** |
1237 * Appends the given character to the data. | 1237 * Appends the given character to the data. |
1238 */ | 1238 */ |
1239 void write(char i) { | 1239 void write(char i) { |
1240 buffer.append(i); | 1240 buffer.format("{}", i); |
1241 } | 1241 } |
1242 /** | 1242 /** |
1243 * Appends the specified line text to the data. | 1243 * Appends the specified line text to the data. |
1244 * | 1244 * |
1245 * @param line line text to write. Must not contain line breaks | 1245 * @param line line text to write. Must not contain line breaks |
1938 lfIndex = text.indexOf (DWT.LF, i); | 1938 lfIndex = text.indexOf (DWT.LF, i); |
1939 } | 1939 } |
1940 if (lfIndex is -1 && crIndex is -1) { // no more line breaks? | 1940 if (lfIndex is -1 && crIndex is -1) { // no more line breaks? |
1941 break; | 1941 break; |
1942 } else if ((crIndex < lfIndex && crIndex !is -1) || lfIndex is -1) { | 1942 } else if ((crIndex < lfIndex && crIndex !is -1) || lfIndex is -1) { |
1943 convertedText.append(text.substring(i, crIndex)); | 1943 convertedText.format("{}", text.substring(i, crIndex)); |
1944 if (lfIndex is crIndex + 1) { // CR/LF combination? | 1944 if (lfIndex is crIndex + 1) { // CR/LF combination? |
1945 i = lfIndex + 1; | 1945 i = lfIndex + 1; |
1946 } else { | 1946 } else { |
1947 i = crIndex + 1; | 1947 i = crIndex + 1; |
1948 } | 1948 } |
1949 } else { // LF occurs before CR! | 1949 } else { // LF occurs before CR! |
1950 convertedText.append(text.substring(i, lfIndex)); | 1950 convertedText.format("{}", text.substring(i, lfIndex)); |
1951 i = lfIndex + 1; | 1951 i = lfIndex + 1; |
1952 } | 1952 } |
1953 if (isSingleLine()) { | 1953 if (isSingleLine()) { |
1954 break; | 1954 break; |
1955 } | 1955 } |
1956 convertedText.append(delimiter); | 1956 convertedText.format("{}", delimiter); |
1957 } | 1957 } |
1958 // copy remaining text if any and if not in single line mode or no | 1958 // copy remaining text if any and if not in single line mode or no |
1959 // text copied thus far (because there only is one line) | 1959 // text copied thus far (because there only is one line) |
1960 if (i < length && (!isSingleLine() || convertedText.length() is 0)) { | 1960 if (i < length && (!isSingleLine() || convertedText.length() is 0)) { |
1961 convertedText.append(text.substring(i)); | 1961 convertedText.format("{}", text.substring(i)); |
1962 } | 1962 } |
1963 return convertedText.toString(); | 1963 return convertedText.toString(); |
1964 } | 1964 } |
1965 bool checkDragDetect(Event event) { | 1965 bool checkDragDetect(Event event) { |
1966 if (!isListening(DWT.DragDetect)) return false; | 1966 if (!isListening(DWT.DragDetect)) return false; |