private void OnPreviewViewportDraw(Device device, SpriteBatch spriteBatch, Rectangle cliprectangle) { UiEncodingWindowSource source = _currentSource; if (source == null) { return; } spriteBatch.Begin(SpriteSortMode.Deferred, null, _previewViewport.DxControl.RenderContainer.GraphicsDevice.SamplerStates.PointClamp, null, null, null, SharpDX.Matrix.Scaling(_scale)); float x = 0, maxX = 0; float y = source.Info.Header.LineSpacing; int squareSize = source.Info.Header.SquareSize; int lineSpacing = source.Info.Header.LineHeight + source.Info.Header.LineSpacing; foreach (char ch in _previewText) { if (ch == '\r') { continue; } if (ch == '\n') { x = 0; y += lineSpacing; continue; } short index; if (source.Codes.TryGetValue(ch, out index)) { int ox, oy; int h, w; if (index < 256) { byte before, width, after; source.Info.GetSizes(index, out before, out width, out after); w = width; h = source.Info.Header.LineHeight; if (before > 0x7F) { x = Math.Max(x - (0xFF - before), 0); } else { x += before; } source.Info.GetOffsets(index, out ox, out oy); source.Texture.Draw(device, spriteBatch, new Vector2(x, y), new Rectangle(ox, oy, w, h), 0, cliprectangle); if (after > 0x7F) { x = Math.Max(x - (0xFF - after), 0); } else { x += after; } } else { index -= 256; w = h = squareSize; int value = source.Info.AdditionalTable[index]; ox = (value & 0xFF) * squareSize; oy = (value >> 8) * squareSize; source.Texture.Draw(device, spriteBatch, new Vector2(x, y), new Rectangle(ox, oy, w, h), 0, cliprectangle); } x += w; maxX = Math.Max(x, maxX); } } spriteBatch.End(); double desiredWidth, desiredHeight; _previewViewport.GetDesiredSize(out desiredWidth, out desiredHeight); double newDesiredWidth = x * _scale; double newDesiredHeight = (y + lineSpacing) * _scale; if (Math.Abs(newDesiredWidth - desiredWidth) > 1 || Math.Abs(newDesiredHeight - newDesiredHeight) > 1) { _previewViewport.SetDesiredSize(newDesiredWidth, newDesiredHeight); } }
private void OnComboBoxItemChanged(object sender, EventArgs e) { _currentSource = (UiEncodingWindowSource)_comboBox.SelectedItem; _charactersControl.SetCurrent(_currentSource, new int[0], new int[0]); _editViewport.SetDesiredSize(_currentSource.Texture.Descriptor2D.Width, _currentSource.Texture.Descriptor2D.Height); }