How to draw label bigger size? - unity3d

I am working with Unity and I try to output some info, in order to do this I draw label
void OnGUI()
{
GUI.Label(new Rect(10, 10, 300, 100), FpsDecoded.ToString("D3")+" FPS Decoded" + (buffereing?" Bufferring...":""));
}.
As a result I see label with output info, but problem is that size of this label very small...
and whatever I do, nothing work. I tried to apply different Rect sizes , but text size doesn't changes
What am I doing wrong?

Eventually I solved it this way
private GUIStyle guiStyle = new GUIStyle(); //create a new variable
void OnGUI()
{
guiStyle.fontSize = 20;
string text = FpsDecoded.ToString("D3") + " FPS Decoded" + (buffereing ? " Bufferring..." : "");
GUI.Label(new Rect(10, 10, 300, 100), text, guiStyle);
}

Related

Drawing a Rectangle with color and thickness in OnGUI

I would like to draw a frame / rectangle in OnGUI in order to display a certain area for debugging purposes.
This rectangle should be displayed with a certain "thickness" / line width and color.
So far, I have only found GUI.Label and GUI.Box, which both seems inadequate for this.
Thank you!
If it is only for debugging I would recommend to use Gizmos.DrawWireCube
Note: Only drawn in the SceneView not in the GameView so really only for debugging
private void OnDrawGizmosSelected()
{
// Draw a yellow cube at the transform position
var color = Gizmos.color;
Gizmos.color = Color.yellow;
Gizmos.DrawWireCube(transform.position, new Vector3(1, 1, 1));
Gizmos.color = color;
}
for showing it only if object is selected or OnDrawGizmos for showing it allways
Note that this is done in WorldSpace so if you rather want the size vector etc rotate together with the object you can wrap in between
var matrix = Gizmos.matrix;
Gizmos.matrix = transform.localToWorldMatrix;
//...
Gizmos.matrix = matrix;
Unfortunately there is no option to change the line thikness...
... but you could overcome this by simply drawing e.g. 4 normal cubes using Gizmos.DrawCube to form a rectangle. Something maybe like
private void OnDrawGizmos()
{
DrawDebugRect(new Vector2(0.5f, 0.3f), 0.05f);
}
private void DrawRect(Vector2 size, float thikness)
{
var matrix = Gizmos.matrix;
Gizmos.matrix = transform.localToWorldMatrix;
//top cube
Gizmos.DrawCube(Vector3.up * size.y / 2, new Vector3(size.x, thikness, 0.01f);
//bottom cube
Gizmos.DrawCube(Vector3.down * size.y / 2, new Vector3(size.x, thikness, 0.01f);
//left cube
Gizmos.DrawCube(Vector3.left * size.x / 2, new Vector3(thikness, size.y, 0.01f);
//right cube
Gizmos.DrawCube(Vector3.right * size.x / 2, new Vector3(thikness, size.y, 0.01f);
Gizmos.matrix = matrix;
}
I'm only on smartphone so it might not be copy-past-able but I think you'll get the idea ;)

Not seeing blank signature field added to PDF

I am replacing TextFields to Signature fields and not able to see these blank signature fields in the generated PDF.
These blank fields will be needed to digitally signed by client at later stages.
/// <summary>
/// Adds a text field to the report that the user can update signatures to the specified location.
/// </summary>
/// <param name="writer">pdfwriter of document.</param>
/// <param name="xPosition">The lower left x position of the text field.</param>
/// <param name="yPosition">The lower left y position of the text field.</param>
/// <param name="width">The width of the text field.</param>
/// <param name="height">The height of the text field.</param>
/// <param name="fieldId"></param>
protected virtual void AddTextField(iTextSharp.text.pdf.PdfWriter writer, String fieldId, float xPosition, float yPosition, float width, float height)
{
Rectangle position = new Rectangle(xPosition, yPosition, xPosition + width, Math.Max(yPosition - height, 0));
iTextSharp.text.pdf.TextField field = new iTextSharp.text.pdf.TextField(writer, position, fieldId);
// Requirement is to change existing textFields to blank Signature fields
// In the method, memoryStream, reader and stamper are not available.
// Below is the textField I need to transform into Signature field.
// field.Text = String.Empty;
// field.Font = FontFactory.GetFont("Arial Narrow").BaseFont;
// field.TextColor = Color.WHITE;
// field.FontSize = 9;
// Not seeing the signature field appear on the pdf.
// Don't know exactly the reason
PdfFormField sig = PdfFormField.CreateSignature(writer);
sig.SetWidget(position, null);
sig.Flags = PdfAnnotation.FLAGS_PRINT;
sig.Put(PdfName.DA, new PdfString("/Helv 0 Tf 0 g"));
sig.FieldName = fieldId;
sig.SetPage();
writer.AddAnnotation(sig);
//Also tried below code
//PdfFormField pfield = PdfFormField.CreateSignature(writer);
//pfield.FieldName = fieldId;
//pfield.SetFieldFlags(PdfAnnotation.FLAGS_PRINT);
//pfield.SetWidget(position, null);
//pfield.SetPage();
//pfield.MKBorderColor = Color.BLACK;
//pfield.MKBackgroundColor = Color.BLUE;
//PdfAppearance tp = PdfAppearance.CreateAppearance(writer, width, height);
//tp.Rectangle(position);
//tp.Stroke();
//pfield.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, tp);
//writer.AddAnnotation(pfield);
}
Second quest:
*Do I really need a signature field if - client will add signature text to these field at later stages (using 3rd party tool like DocuSign)? or simple PDFTextFields would really work?
Adding above question with the query as this may be helpful in relating my scenario.
Thanks in advance for the help.
I just tested your code using
public void AddSignatureFieldLikePrashantJha()
{
Document document = new Document();
Stream stream = new FileStream(#"emptySignatureFieldLikePrashantJha.pdf", FileMode.Create);
PdfWriter pdfWriter = PdfWriter.GetInstance(document, stream);
document.Open();
AddTextField(pdfWriter, "Signature", 100, 100, 400, 50);
document.Close();
}
In the result Adobe Reader DC clearly indicated the signature field position by an arrow:
Putting the focus to that field (e.g. by pressing TAB) the field even is given a frame:
Earlier Adobe Reader versions show it even clearer, e.g. 9.5:
Thus, I cannot reproduce that you are
not able to see these blank signature fields in the generated PDF
If you want to have the field area appear somehow more pronounced, you can indeed use a PdfAppearance, e.g.
protected virtual void AddFancySignatureField(iTextSharp.text.pdf.PdfWriter writer, String fieldId, float xPosition, float yPosition, float width, float height)
{
Rectangle position = new Rectangle(xPosition, yPosition, xPosition + width, Math.Max(yPosition - height, 0));
iTextSharp.text.pdf.TextField field = new iTextSharp.text.pdf.TextField(writer, position, fieldId);
PdfFormField sig = PdfFormField.CreateSignature(writer);
sig.SetWidget(position, null);
sig.Flags = PdfAnnotation.FLAGS_PRINT;
sig.Put(PdfName.DA, new PdfString("/Helv 0 Tf 0 g"));
sig.FieldName = fieldId;
sig.SetPage();
PdfAppearance tp = PdfAppearance.CreateAppearance(writer, width, height);
PdfShading radial = PdfShading.SimpleRadial(writer, 0, height / 2, 0, 0, height / 2, width, BaseColor.RED, BaseColor.GREEN);
tp.PaintShading(radial);
sig.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, tp);
writer.AddAnnotation(sig);
}
The result looks like this:
Second quest: *Do I really need a signature field if - client will add signature text to these field at later stages (using 3rd party tool like DocuSign)? or simple PDFTextFields would really work?
That depends very much on the exact 3rd party tool used. Some such tools require signature fields, some require a text marker in the content, some want the position given by coordinate...

How to use DrawNode with RenderTexture cocos2d-x

I cannot draw a simple line or a dot with DrawNode and RenderTexture.
This is how to I implemented:
AppDelegate.cpp
auto scene = Scene::create();
auto layer = BackgroundLayer::create();
scene->addChild(layer);
// run
director->runWithScene(scene);
BackgroundLayer.cpp
bool BackgroundLayer::init()
{
if ( !LayerColor::initWithColor(Color4B::WHITE) )
{
return false;
}
auto renderTexture = RenderTexture::create(300, 200);
renderTexture->beginWithClear(0, 0, 0, 1); // black
auto drawPrimitive = DrawNode::create();
drawPrimitive->retain();
drawPrimitive->drawDot(Point(250, 250), 20, Color4F::RED);
drawPrimitive->visit();
renderTexture->end();
renderTexture->retain();
renderTexture->setPosition(this->getContentSize()/2);
this->addChild(renderTexture, 10000);
}
I tried with some complex shape with DrawNode, but the result is just a black rectangle stayed in the center of the screen.
I compile with cocos2d-x v3.6 & VS2013.
auto renderTexture = RenderTexture::create(50, 50);
renderTexture->beginWithClear(0, 0, 0, 1); // black
auto drawPrimitive = DrawNode::create();
drawPrimitive->retain();
drawPrimitive->drawDot(Point(10, 10), 2, Color4F::RED);
drawPrimitive->visit();
renderTexture->end();
renderTexture->retain();
renderTexture->setPosition(SCREENSIZE.width/2,SCREENSIZE.height/2);
this->addChild(renderTexture, 10000);
Try this it will create red dot on the texture

Unity3d stretch GUI.Box

I newby to Unity and I write a simple tic-tac-toe game for mobile devices.
I have troubles with GUI.Box. I try to make it stretch, but it does not work and text is clipped. My code:
GUIStyle lBoxStyle = new GUIStyle(GUI.skin.box);
lBoxStyle.stretchWidth = true;
lBoxStyle.stretchHeight = true;
lBoxStyle.wordWrap = true;
lBoxStyle.fontSize = 48;
lBoxStyle.normal.textColor = Color.black;
GUI.Box(new Rect((virtualWidth - mBoxWidth) / 2, (virtualHeight - mBoxHeight) / 2, mBoxWidth, mBoxHeight), mAlert, lBoxStyle);
How can I fix it?Also how I can reduce size if text is short?
First find out what is the size of the content with CalcSize. Then use that size to make the box tightly fitted around the content.
GUIStyle lBoxStyle = new GUIStyle(GUI.skin.box);
lBoxStyle.stretchWidth = true;
lBoxStyle.stretchHeight = true;
lBoxStyle.wordWrap = true;
lBoxStyle.fontSize = 48;
lBoxStyle.normal.textColor = Color.Black;
// Caculate the size of the content
Vector2 size = lBoxStyle.CalcSize(new GUIContent(mAlert));
// Padding if needed
// size += new Vector2(10, 10)
// Use the size as the size of the element
GUI.Box(new Rect((virtualWidth - size.x) / 2, (virtualHeight - size.y) / 2, size.x, size.y), mAlert, lBoxStyle);

iTextSharp - Some pages not stamped as expected

I'm using iTextSharp 5.0.6 to read an existing PDF, iterate each page stamping text on each, and then writing out the newly stamped PDF. The issue I'm faced with is that this isn't working 100% of the time. For some PDFs every page is stamped as expected, for others most pages are stamped while some are not. Seems as if there's potentially an issue where the stamper's GetOverContent() is not returning the top-most layer, but that's just an assumption. Has anyone had a similar issue?
using iTextSharp.text;
using iTextSharp.text.pdf;
const string WATERMARK_TEXT = "John Doe";
static void Main(string[] args)
{
string masterPdf = "master.pdf";
string pdfToCreate = "watermark.pdf";
byte[] bytes = StampPDF(masterPdf);
using (FileStream stream = new FileStream(pdfToCreate, FileMode.Create))
{
stream.Write(bytes, 0, bytes.Length);
}
}
static byte[] StampPDF(string PdfPath)
{
using (MemoryStream memoryStream = new MemoryStream())
{
PdfReader reader = new PdfReader(PdfPath);
int pageCount = reader.NumberOfPages;
PdfStamper stamper = new PdfStamper(reader, memoryStream);
float fontSize = 9;
float textAngle = 0f;
BaseFont font = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.WINANSI, BaseFont.EMBEDDED);
BaseColor backgroundColor = new BaseColor(0, 0, 0);
BaseColor fontColor = new BaseColor(255, 255, 255);
float padding = 2f;
float fontWidth = font.GetWidthPoint(WATERMARK_TEXT, fontSize);
iTextSharp.text.Rectangle pageSize;
PdfContentByte pageContents;
for (int i = 1; i <= pageCount; i++)
{
pageSize = reader.GetPageSize(i);
pageContents = stamper.GetOverContent(i);
//draw a rectangle
pageContents.SetColorFill(backgroundColor);
pageContents.MoveTo(pageSize.Width - (fontWidth + padding), 0f);
pageContents.LineTo(pageSize.Width, 0f);
pageContents.LineTo(pageSize.Width, 14f);
pageContents.LineTo(pageSize.Width - (fontWidth + padding), 14f);
pageContents.Fill();
//drop our watermark on top of the rectangle we just created
pageContents.BeginText();
pageContents.SetColorFill(fontColor);
pageContents.SetFontAndSize(font, fontSize);
pageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, WATERMARK_TEXT, pageSize.Width - fontWidth, 4, textAngle);
pageContents.EndText();
}
stamper.Close();
reader.Close();
return memoryStream.ToArray();
}
}
For those that may encounter the same problem the key is inspecting the CropBox. Since the dimensions of a PDF's CropBox may be less than that of its PageSize you need to conditionally use one or the other. So, based on the code sample above the for loop would be altered as so:
for (int i = 1; i <= pageCount; i++)
{
mediaBox = reader.GetPageSize(i);
cropBox = reader.GetCropBox(i);
overContent = stamper.GetOverContent(i);
if (cropBox != null && (cropBox.Width < mediaBox.Width || cropBox.Height < cropBox.Height))
mediaBox = cropBox;
//draw a rectangle
overContent.SetColorFill(backgroundColor);
overContent.MoveTo(mediaBox.Right - (fontWidth + fontPadding), mediaBox.Bottom);
overContent.LineTo(mediaBox.Right, mediaBox.Bottom);
overContent.LineTo(mediaBox.Right, mediaBox.Bottom + rectangleHeight);
overContent.LineTo(mediaBox.Right - (fontWidth + fontPadding), mediaBox.Bottom + rectangleHeight);
overContent.ClosePathFillStroke();
//drop our watermark on top of the rectangle we just created
overContent.BeginText();
overContent.SetColorFill(fontColor);
overContent.SetFontAndSize(font, fontSize);
overContent.ShowTextAligned(PdfContentByte.ALIGN_LEFT, WATERMARK_TEXT, mediaBox.Right - fontWidth, mediaBox.Bottom + (rectangleHeight - fontSize), textAngle);
overContent.EndText();
}
You've made two mistakes:
You're assuming that the pages aren't rotated, but they can be: 90, 180, 270. Note that I've never seen a 180 page, but its legal. When drawing to a rotated page, you have to take that rotation into account when drawing on it. Fun with transformation matrices.
You're assuming that the page's (unrotated) lower left corner is 0,0. You're basing your measurements on the page's width and height (close), but aren't adjusting for any offset in that bottom left corner.
There are three ways to do a landscape page:
11"x8.5"
8.5"x11" # 90 degrees rotation
8.5"x11" # 270 degrees rotation
Technically, a 4th way is to build an 11x8.5 # 180, but anyone writing such code should be Punished. A lot.
There are various SO questions floating about that give details on how to deal with page rotation. Going by your code, I'd say you'll figure out the llx,lly thing pretty quickly.