private PcbText ReadFootprintString(BinaryReader reader, List <string> wideStrings) { var result = ReadBlock(reader, recordSize => { CheckValue(nameof(recordSize), recordSize, 43, 123, 226, 230); var text = new PcbText(); ReadFootprintCommon(reader, text); text.Corner1 = ReadCoordPoint(reader); var height = reader.ReadInt32(); text.Corner2 = new CoordPoint( Coord.FromInt32(text.Corner1.X.ToInt32()), Coord.FromInt32(text.Corner1.Y.ToInt32() + height)); text.StrokeFont = (PcbTextStrokeFont)reader.ReadInt16(); text.Rotation = reader.ReadDouble(); text.Mirrored = reader.ReadBoolean(); text.StrokeWidth = reader.ReadInt32(); if (recordSize >= 123) { reader.ReadUInt16(); // TODO: Unknown reader.ReadByte(); // TODO: Unknown text.TextKind = (PcbTextKind)reader.ReadByte(); text.FontBold = reader.ReadBoolean(); text.FontItalic = reader.ReadBoolean(); text.FontName = ReadStringFontName(reader); // TODO: check size and string format text.BarcodeLRMargin = reader.ReadInt32(); text.BarcodeTBMargin = reader.ReadInt32(); reader.ReadInt32(); // TODO: Unknown - Coord 0? reader.ReadInt32(); // TODO: Unknown - Coord 4mil? reader.ReadByte(); // TODO: Unknown reader.ReadByte(); // TODO: Unknown reader.ReadInt32(); // TODO: Unknown - Coord? reader.ReadUInt16(); // TODO: Unknown reader.ReadInt32(); // TODO: Unknown 1 reader.ReadInt32(); // TODO: Unknown text.FontInverted = reader.ReadBoolean(); text.FontInvertedBorder = reader.ReadInt32(); text.WideStringsIndex = reader.ReadInt32(); reader.ReadInt32(); // TODO: Unknown text.FontInvertedRect = reader.ReadBoolean(); text.FontInvertedRectWidth = reader.ReadInt32(); text.FontInvertedRectHeight = reader.ReadInt32(); text.FontInvertedRectJustification = (PcbTextJustification)reader.ReadByte(); text.FontInvertedRectTextOffset = reader.ReadInt32(); } return(text); }); var asciiText = ReadStringBlock(reader); // non-unicode Text if (result.WideStringsIndex < wideStrings?.Count) { result.Text = wideStrings[result.WideStringsIndex]; } else { result.Text = asciiText; } return(result); }
private void RenderTextPrimitive(Graphics g, PcbText text) { var location = ScreenFromWorld(text.Corner1.X, text.Corner1.Y); var color = LayerMetadata.GetColor(text.Layer); var height = ScaleCoord(text.Height); var fontStyle = (text.FontItalic ? FontStyle.Italic : FontStyle.Regular) | (text.FontBold ? FontStyle.Bold : FontStyle.Regular); float fontWidth; float fontSize; if (text.TextKind == PcbTextKind.Stroke) { fontWidth = ScaleCoord(text.Width); fontSize = DrawingUtils.CalculateFontSizeForBaseline(g, StrokeFontFamily, fontStyle, height + fontWidth); } else { fontWidth = 0; fontSize = DrawingUtils.CalculateFontSizeForHeight(g, StrokeFontFamily, fontStyle, height); } g.TranslateTransform(location.X, location.Y); g.RotateTransform(-(float)text.Rotation); using (var brush = new SolidBrush(color)) using (var fontFamily = new FontFamily(text.FontName)) using (var font = new Font(text.TextKind == PcbTextKind.Stroke ? StrokeFontFamily : fontFamily, fontSize, fontStyle)) { var size = g.MeasureString(text.Text, font); if (size.Height < 5) { using (var pen = new Pen(brush)) { var rect = ScaleRect(text.CalculateRect(false)); g.DrawRectangle(pen, rect.Left, rect.Top, rect.Width, rect.Height); } } else { if (text.Mirrored) { g.ScaleTransform(-1.0f, 1.0f); } DrawingUtils.DrawString(g, text.Text, font, brush, 0, fontWidth * 0.5f, StringAlignmentKind.Tight, StringAlignment.Near, StringAlignment.Far); } } g.ResetTransform(); }
private void WriteFootprintText(BinaryWriter writer, PcbText text) { WriteBlock(writer, w => { WriteFootprintCommon(w, text, text.Corner1); w.Write(text.Height.ToInt32()); w.Write((short)text.StrokeFont); w.Write((double)text.Rotation); w.Write(text.Mirrored); w.Write(text.StrokeWidth.ToInt32()); //recordSize >= 123 w.Write((short)0); // TODO: Unknown w.Write((byte)0); // TODO: Unknown w.Write((byte)text.TextKind); w.Write(text.FontBold); w.Write(text.FontItalic); WriteStringFontName(w, text.FontName); // TODO: check size and string format w.Write(text.BarcodeLRMargin.ToInt32()); w.Write(text.BarcodeTBMargin.ToInt32()); w.Write(0); // TODO: Unknown - Coord 0? w.Write(Coord.FromMils(4)); // TODO: Unknown - Coord 4mil? w.Write((byte)0); // TODO: Unknown w.Write((byte)0); // TODO: Unknown w.Write(0); // TODO: Unknown - Coord? w.Write((short)0); // TODO: Unknown w.Write(1); // TODO: Unknown 1? w.Write(0); // TODO: Unknown w.Write(text.FontInverted); w.Write(text.FontInvertedBorder.ToInt32()); w.Write(text.WideStringsIndex); w.Write(0); // TODO: Unknown w.Write(text.FontInvertedRect); w.Write(text.FontInvertedRectWidth.ToInt32()); w.Write(text.FontInvertedRectHeight.ToInt32()); w.Write((byte)text.FontInvertedRectJustification); w.Write(text.FontInvertedRectTextOffset.ToInt32()); }); WriteStringBlock(writer, text.Text); }