# HG changeset patch # User Frank Benoit # Date 1219336178 -7200 # Node ID 57cb6d948bf7d86445c0a26db390dcb67df6a71d # Parent 8907b637425818f5ff748cf107c639feb1baa6cf Fix visible OBJECT REPLACEMENT CHARACTER. In utf8 length is 2, which needed to be take care of in style.length. diff -r 8907b6374258 -r 57cb6d948bf7 snippets/styledtext/Snippet212.d --- a/snippets/styledtext/Snippet212.d Thu Aug 21 17:49:33 2008 +0200 +++ b/snippets/styledtext/Snippet212.d Thu Aug 21 18:29:38 2008 +0200 @@ -70,11 +70,13 @@ import dwt.dwthelper.utils; import dwt.dwthelper.System; +const char[] OBJ_MARKER = "\uFFFC"; + void main() { static StyledText styledText; static String text = "This snippet shows how to embed images in a StyledText.\n" - "Here is one: \uFFFC, and here is another: \uFFFC." + "Here is one: " ~ OBJ_MARKER ~ ", and here is another: " ~ OBJ_MARKER ~ "." "Use the add button to add an image from your filesystem to the StyledText at the current caret offset."; static Image[] images; static int[] offsets; @@ -82,7 +84,7 @@ static void addImage(Image image, int offset) { StyleRange style = new StyleRange (); style.start = offset; - style.length = 1; + style.length = OBJ_MARKER.length; Rectangle rect = image.getBounds(); style.metrics = new GlyphMetrics(rect.height, 0, rect.width); styledText.setStyleRange(style); @@ -101,7 +103,7 @@ offsets = new int[images.length]; int lastOffset = 0; for (int i = 0; i < images.length; i++) { - int offset = text.indexOf("\uFFFC", lastOffset); + int offset = text.indexOf(OBJ_MARKER, lastOffset); offsets[i] = offset; addImage(images[i], offset); lastOffset = offset + 1; @@ -162,7 +164,7 @@ try { Image image = new Image(display, filename); int offset = styledText.getCaretOffset(); - styledText.replaceTextRange(offset, 0, "\uFFFC"); + styledText.replaceTextRange(offset, 0, OBJ_MARKER); int index = 0; while (index < offsets.length) { if (offsets[index] == -1 && images[index] is null) break; @@ -182,7 +184,7 @@ } catch (Exception e) { ExceptionPrintStackTrace(e); } - } + } } button.addListener(DWT.Selection, dgListener(&onSelection)); shell.setSize(400, 400);