Gma.QrCodeNet.Encoder/Windows/Render/EncapsulatedPostScriptRenderer.cs
/// <summary>
/// Draw a square for each dark module
/// </summary>
/// <param name="matrix">The matrix to be rendered</param>
/// <param name="stream">Output text stream</param>
Draw a square for each dark module
Draw a square for each dark module
private void DrawSquares(BitMatrix matrix, StreamWriter stream)
		{
			string strSquaresHeader = @"
% Draw squares
{0} 255 div {1} 255 div {2} 255 div setrgbcolor
q q translate";
			stream.WriteLine(string.Format(strSquaresHeader,
				DarkColor.R,
				DarkColor.G,
				DarkColor.B));
			for (int y = 0; y < matrix.Height; ++y)
			{
				for (int x = 0; x < matrix.Width; ++x)
				{
					if (matrix[x, y]) 
					{
						bool bHasRightNeighbor = x + 1 < matrix.Width && matrix[x + 1, y];
						bool bHasBottomNeighbor = y + 1 < matrix.Height && matrix[x, y + 1];
						stream.WriteLine(string.Format("{0} {1} b{2}{3}", x, y, bHasRightNeighbor ? "r" : "", bHasBottomNeighbor ? "b" : ""));
					}
				}
			}
		}
private void DrawSquares ( BitMatrix matrix , StreamWriter stream ) { string strSquaresHeader = @"
% Draw squares
{0} 255 div {1} 255 div {2} 255 div setrgbcolor
q q translate" ; stream . WriteLine ( string . Format ( strSquaresHeader , DarkColor . R , DarkColor . G , DarkColor . B ) ) ; for ( int y = 0 ; y < matrix . Height ; ++ y ) { for ( int x = 0 ; x < matrix . Width ; ++ x ) { if ( matrix [ x , y ] ) { bool bHasRightNeighbor = x + 1 < matrix . Width && matrix [ x + 1 , y ] ; bool bHasBottomNeighbor = y + 1 < matrix . Height && matrix [ x , y + 1 ] ; stream . WriteLine ( string . Format ( " " , x , y , bHasRightNeighbor ? " " : " " , bHasBottomNeighbor ? " " : " " ) ) ; } } } }
Draw a square for each dark module
Draw a square for each dark module
// Only draw dark modules // If the dark module has a dark neighbor on the right, make the two boxed overlap 1% by calling "br" instead of simply "b" // Same applies for bottom neighbor with "bb" command, or "brb" for right and bottom dark neighbors. // Overlapping two modules avoids having tiny gaps appearing on certain zoom scales or output devices. // Output the coordinates of the upper left corner and call to the box function
matrix
BitMatrix
The matrix to be rendered
The matrix to be rendered
stream
StreamWriter
Output text stream
Output text stream