public void TextUtilsRender() { tlog.Debug(tag, $"TextUtilsRender START"); TextLabel label = new TextLabel() { Size = new Size(50, 20), Text = "TextUtilsGetLastCharacterIndex" }; RendererParameters textParameters = new RendererParameters(); textParameters.Text = label.Text; textParameters.TextWidth = (uint)label.Size.Width; textParameters.TextHeight = (uint)label.Size.Height; textParameters.Layout = TextLayout.MultiLine; textParameters.EllipsisEnabled = true; EmbeddedItemInfo[] embeddedItemLayout = new EmbeddedItemInfo[3]; var result = TextUtils.Render(textParameters, ref embeddedItemLayout); Assert.IsNotNull(result, "Can't create success object PixelBuffer"); Assert.IsInstanceOf <PixelBuffer>(result, "Should be an instance of PixelBuffer type."); tlog.Debug(tag, $"TextUtilsRender END (OK)"); }
public void TextUtilsEmbeddedItemInfoConstructor() { tlog.Debug(tag, $"TextUtilsEmbeddedItemInfoConstructor START"); var testingTarget = new EmbeddedItemInfo(); Assert.IsNotNull(testingTarget, "Can't create success object EmbeddedItemInfo"); Assert.IsInstanceOf <EmbeddedItemInfo>(testingTarget, "Should be an instance of EmbeddedItemInfo type."); testingTarget.Dispose(); tlog.Debug(tag, $"TextUtilsEmbeddedItemInfoConstructor END (OK)"); }
public void TextUtilsEmbeddedItemInfoAngle() { tlog.Debug(tag, $"TextUtilsEmbeddedItemInfoAngle START"); var testingTarget = new EmbeddedItemInfo(); Assert.IsNotNull(testingTarget, "Can't create success object EmbeddedItemInfo"); Assert.IsInstanceOf <EmbeddedItemInfo>(testingTarget, "Should be an instance of EmbeddedItemInfo type."); testingTarget.Angle = new Degree(30.0f); Assert.AreEqual(30.0f, testingTarget.Angle.Value, "Should be equal!"); testingTarget.Dispose(); tlog.Debug(tag, $"TextUtilsEmbeddedItemInfoAngle END (OK)"); }
public void TextUtilsEmbeddedItemInfoGlyphIndex() { tlog.Debug(tag, $"TextUtilsEmbeddedItemInfoGlyphIndex START"); var testingTarget = new EmbeddedItemInfo(); Assert.IsNotNull(testingTarget, "Can't create success object EmbeddedItemInfo"); Assert.IsInstanceOf <EmbeddedItemInfo>(testingTarget, "Should be an instance of EmbeddedItemInfo type."); testingTarget.GlyphIndex = 911; Assert.AreEqual(911, testingTarget.GlyphIndex, "Should be equal!"); testingTarget.Dispose(); tlog.Debug(tag, $"TextUtilsEmbeddedItemInfoGlyphIndex END (OK)"); }
public void TextUtilsEmbeddedItemInfoRotatedSize() { tlog.Debug(tag, $"TextUtilsEmbeddedItemInfoRotatedSize START"); var testingTarget = new EmbeddedItemInfo(); Assert.IsNotNull(testingTarget, "Can't create success object EmbeddedItemInfo"); Assert.IsInstanceOf <EmbeddedItemInfo>(testingTarget, "Should be an instance of EmbeddedItemInfo type."); testingTarget.RotatedSize = new Size(100.0f, 200.0f); Assert.AreEqual(100.0f, testingTarget.RotatedSize.Width, "Should be equal!"); Assert.AreEqual(200.0f, testingTarget.RotatedSize.Height, "Should be equal!"); testingTarget.Dispose(); tlog.Debug(tag, $"TextUtilsEmbeddedItemInfoRotatedSize END (OK)"); }
public void TextUtilsEmbeddedItemInfoPosition() { tlog.Debug(tag, $"TextUtilsEmbeddedItemInfoPosition START"); var testingTarget = new EmbeddedItemInfo(); Assert.IsNotNull(testingTarget, "Can't create success object EmbeddedItemInfo"); Assert.IsInstanceOf <EmbeddedItemInfo>(testingTarget, "Should be an instance of EmbeddedItemInfo type."); testingTarget.Position = new Vector2(100.0f, 200.0f); Assert.AreEqual(100.0f, testingTarget.Position.X, "Should be equal!"); Assert.AreEqual(200.0f, testingTarget.Position.Y, "Should be equal!"); testingTarget.Dispose(); tlog.Debug(tag, $"TextUtilsEmbeddedItemInfoPosition END (OK)"); }
public void TextUtilsEmbeddedItemInfoColorBlendingModee() { tlog.Debug(tag, $"TextUtilsEmbeddedItemInfoColorBlendingModee START"); var testingTarget = new EmbeddedItemInfo(); Assert.IsNotNull(testingTarget, "Can't create success object EmbeddedItemInfo"); Assert.IsInstanceOf <EmbeddedItemInfo>(testingTarget, "Should be an instance of EmbeddedItemInfo type."); testingTarget.ColorBlendingMode = Tizen.NUI.ColorBlendingMode.Multiply; Assert.AreEqual(Tizen.NUI.ColorBlendingMode.Multiply, testingTarget.ColorBlendingMode, "Should be equal!"); testingTarget.ColorBlendingMode = Tizen.NUI.ColorBlendingMode.None; Assert.AreEqual(Tizen.NUI.ColorBlendingMode.None, testingTarget.ColorBlendingMode, "Should be equal!"); testingTarget.Dispose(); tlog.Debug(tag, $"TextUtilsEmbeddedItemInfoColorBlendingModee END (OK)"); }
TextureSet CreateTextureSet(RendererParameters textParameters, List <string> embeddedItems) { EmbeddedItemInfo[] embeddedItemLayout = new EmbeddedItemInfo[0]; PixelBuffer pixelBuffer = TextUtils.Render(textParameters, ref embeddedItemLayout); uint dstWidth = pixelBuffer.GetWidth(); uint dstHeight = pixelBuffer.GetHeight(); int index = 0; int length = embeddedItemLayout.Length; for (int i = 0; i < length; i++) { EmbeddedItemInfo itemLayout = embeddedItemLayout[i]; int width = (int)itemLayout.Size.Width; int height = (int)itemLayout.Size.Height; int x = (int)itemLayout.Position.X; int y = (int)itemLayout.Position.Y; PixelBuffer itemPixelBuffer = ImageLoading.LoadImageFromFile(embeddedItems[index++]); if (itemPixelBuffer == null) { continue; } itemPixelBuffer.Resize((ushort)width, (ushort)height); itemPixelBuffer.Rotate(itemLayout.Angle); width = (int)itemPixelBuffer.GetWidth(); height = (int)itemPixelBuffer.GetHeight(); PixelFormat itemPixelFormat = itemPixelBuffer.GetPixelFormat(); // Check if the item is out of the buffer. if ((x + width < 0) || (x > dstWidth) || (y < 0) || (y - height > dstHeight)) { // The embedded item is completely out of the buffer. continue; } // Crop if it exceeds the boundaries of the destination buffer. int layoutX = 0; int layoutY = 0; int cropX = 0; int cropY = 0; int newWidth = width; int newHeight = height; bool crop = false; if (0 > x) { newWidth += x; cropX = Math.Abs(x); crop = true; } else { layoutX = x; } if (cropX + newWidth > dstWidth) { crop = true; newWidth -= (int)((cropX + newWidth) - dstWidth); } layoutY = y; if (0 > layoutY) { newHeight += layoutY; cropY = Math.Abs(layoutY); crop = true; } if (cropY + newHeight > dstHeight) { crop = true; newHeight -= (int)((cropY + newHeight) - dstHeight); } int uiCropX = cropX; int uiCropY = cropY; int uiNewWidth = newWidth; int uiNewHeight = newHeight; if (crop) { itemPixelBuffer.Crop((ushort)uiCropX, (ushort)uiCropY, (ushort)uiNewWidth, (ushort)uiNewHeight); } // Blend the item pixel buffer with the text's color according its blending mode. if (ColorBlendingMode.Multiply == itemLayout.ColorBlendingMode) { PixelBuffer buffer = new PixelBuffer((uint)uiNewWidth, (uint)uiNewHeight, itemPixelFormat); IntPtr bufferIntPtr = buffer.GetBuffer(); IntPtr itemBufferIntPtr = itemPixelBuffer.GetBuffer(); uint bytesPerPixel = GetBytesPerPixel(itemPixelFormat); uint size = (uint)(uiNewWidth * uiNewHeight * bytesPerPixel); unsafe { byte *bufferPtr = (byte *)bufferIntPtr.ToPointer(); byte *itemBufferPtr = (byte *)itemBufferIntPtr.ToPointer(); for (uint j = 0; j < size; j += bytesPerPixel) { *(bufferPtr + 0) = (byte)((*(itemBufferPtr + 0u)) * textParameters.TextColor.R); *(bufferPtr + 1) = (byte)((*(itemBufferPtr + 1u)) * textParameters.TextColor.G); *(bufferPtr + 2) = (byte)((*(itemBufferPtr + 2u)) * textParameters.TextColor.B); *(bufferPtr + 3) = (byte)((*(itemBufferPtr + 3u)) * textParameters.TextColor.A); itemBufferPtr += bytesPerPixel; bufferPtr += bytesPerPixel; } } itemPixelBuffer = buffer; } TextUtils.UpdateBuffer(itemPixelBuffer, pixelBuffer, (uint)layoutX, (uint)layoutY, true); } PixelData pixelData = PixelBuffer.Convert(pixelBuffer); Texture texture = new Texture(TextureType.TEXTURE_2D, pixelData.GetPixelFormat(), pixelData.GetWidth(), pixelData.GetHeight()); texture.Upload(pixelData); TextureSet textureSet = new TextureSet(); textureSet.SetTexture(0u, texture); return(textureSet); }