9fans.net/go@v0.0.5/draw/doc.go (about)

     1  // Package draw is a port of Plan 9's libdraw to Go.
     2  // It connects to the 'devdraw' binary built as part of
     3  // Plan 9 from User Space (http://swtch.com/plan9port/).
     4  // All graphics operations are done in the remote server.
     5  //
     6  // Displays
     7  //
     8  // Graphics operations are mediated through a Display, obtained by calling Init.
     9  // See the Display documentation for details.
    10  //
    11  // Colors and Pixel Formats
    12  //
    13  // This package represents colors as RGBA values, 8 bits per channel,
    14  // packed into a uint32 type called Color. Color implements the image/color
    15  // package's Color interface.
    16  //
    17  // The images in this package store pixel values in more compact formats
    18  // specified by a pixel format represented by the Pix type.
    19  // (Plan 9 C calls this format a ‘chan’ but that name is already taken in Go.)
    20  // The Pix details the sequence of image channels packed into each pixel.
    21  // For example RGB24, defined as MakePix(CRed, 8, CGreen, 8, CBlue, 8),
    22  // describes a 24-bit pixel format consisting of 8 bits each for red, green, and blue,
    23  // with no explicit alpha channel.
    24  //
    25  // The external representation of a Pix is a string, a sequence of two-character
    26  // channel descriptions, each comprising a letter (r for red, g for green,
    27  // b for blue, a for alpha, m for color-mapped, k for greyscale, and
    28  // x for “don't care”) followed by a number of bits per pixel.
    29  // The sum of the channel bits per pixel is the depth of the image, which
    30  // must be either a divisor or a multiple of eight. It is an error to
    31  // have more than one of any channel but x. An image must have either a
    32  // greyscale channel; a color mapped channel; or red, green, and blue
    33  // channels. If the alpha channel is present, it must be at least as deep
    34  // as any other channel. For example, RGB24 is “r8g8b8”.
    35  //
    36  // The packing of 1-, 2- or 4-bit pixels into bytes is big-endian,
    37  // meaning that the first pixel in a 1-bit image is the 0x80 bit.
    38  // But the packing of 16-, 24-, and 32-bit pixels into byte data
    39  // is little-endian, meaning that the byte order for the RGB24 format
    40  // is actually blue, green, red. This odd convention was chosen for
    41  // compatibility with Plan 9, which in turn chose it for compatibility
    42  // with VGA frame buffers, especially 16-bit pixel data like RGB16.
    43  // Counterintuitively, then, the pixel formats corresponding to Go's
    44  // image.RGBA are ABGR32 or XBGR32.
    45  //
    46  // The color-mapped values, which now are only of historical interest,
    47  // use a 4x4x4 subdivision with 4 shades in each subcube.
    48  // See https://9fans.github.io/plan9port/man/man7/color.html
    49  // for the details.
    50  //
    51  // Image Format
    52  //
    53  // Fonts and images as used by Image.Load, Image.Unload, Display.ReadImage,
    54  // and so on are stored in a machine-independent format defined by Plan 9.
    55  // See https://9fans.github.io/plan9port/man/man7/image.html
    56  // for the details.
    57  //
    58  // Fonts
    59  //
    60  // External bitmap fonts are described by a plain text file that can be
    61  // read using Display.OpenFont.
    62  // See https://9fans.github.io/plan9port/man/man7/font.html
    63  // for the details.
    64  //
    65  // Font Names
    66  //
    67  // Font names in this package (following Plan 9 from User Space) are a
    68  // small language describing a font. The most basic form is the name of
    69  // an existing bitmap font file, following the convention:
    70  //
    71  //	/lib/font/bit/name/range.size.font
    72  //
    73  // where size is approximately the height in pixels of the lower case
    74  // letters (without ascenders or descenders). Range gives some indication
    75  // of which characters will be available: for example ascii, latin1,
    76  // euro, or unicode. Euro includes most European languages, punctuation
    77  // marks, the International Phonetic Alphabet, etc., but no Oriental
    78  // languages. Unicode includes every character for which
    79  // appropriate-sized images exist on the system.
    80  //
    81  // In Plan 9 from User Space, the font files are rooted in $PLAN9/font
    82  // instead of /lib/font/bit, but to keep old references working, paths
    83  // beginning with /lib/font/bit are interpreted as references to the
    84  // actual font directory.
    85  //
    86  // Fonts need not be stored on disk in the Plan 9 format. If the font
    87  // name has the form /mnt/font/name/size/font, fontsrv is invoked to
    88  // synthesize a bitmap font from the operating system's installed vector
    89  // fonts. The command ‘fontsrv -p .’ lists the available fonts.
    90  // See https://9fans.github.io/plan9port/man/man4/fontsrv.html for more.
    91  //
    92  // If the font name has the form scale*fontname, where scale is a small
    93  // decimal integer, the fontname is loaded and then scaled by pixel
    94  // repetition.
    95  //
    96  // The Plan 9 bitmap fonts were designed for screens with pixel density
    97  // around 100 DPI. When used on screens with pixel density above 200 DPI,
    98  // the bitmap fonts are automatically pixel doubled. Similarly, fonts
    99  // loaded from https://9fans.github.io/plan9port/man/man4/fontsrv.html
   100  // are automatically doubled in size by varying
   101  // the effective size path element. In both cases, the effect is that a
   102  // single font name can be used on both low- and high-density displays
   103  // (or even in a window moved between differing displays) while keeping
   104  // roughly the same effective size.
   105  //
   106  // For more control over the fonts used on low- and high-density
   107  // displays, if the font name has the form ‘lowfont,highfont’, then
   108  // lowfont is used on low-density displays and highfont on high-density
   109  // displays. In effect, the behavior described above is that the font
   110  // name
   111  //
   112  //	/lib/font/bit/lucsans/euro.8.font
   113  //
   114  // really means
   115  //
   116  //	/lib/font/bit/lucsans/euro.8.font,2*/lib/font/bit/lucsans/euro.8.font
   117  //
   118  // and similarly
   119  //
   120  //	/mnt/font/LucidaGrande/15a/font
   121  //
   122  // really means
   123  //
   124  //	/mnt/font/LucidaGrande/15a/font,/mnt/font/LucidaGrande/30a/font
   125  //
   126  // Using an explicit comma-separated font pair allows finer control, such
   127  // as using a Plan 9 bitmap font on low-density displays but switching to
   128  // a system-installed vector font on high-density displays:
   129  //
   130  //	/lib/font/bit/lucsans/euro.8.font,/mnt/font/LucidaGrande/30a/font
   131  //
   132  // Libdraw Cheat Sheet
   133  //
   134  // The mapping from the Plan 9 C libdraw names defined in <draw.h>
   135  // to names in this package (omitting unchanged names) is:
   136  //
   137  //	ARROW → Arrow
   138  //	Borderwidth → BorderWidth
   139  //	CACHEAGE → unexported
   140  //	CHAN1, CHAN2, CHAN3, CHAN4 → MakePix
   141  //	Cachefont → unexported
   142  //	Cacheinfo → unexported
   143  //	Cachesubf → unexported
   144  //	DBlack → Black
   145  //	DBlue → Blue
   146  //	DBluegreen → BlueGreen
   147  //	DCyan → Cyan
   148  //	DDarkYellow → DarkYellow
   149  //	DDarkblue → DarkBlue
   150  //	DDarkgreen → DarkGreen
   151  //	DGreen → Green
   152  //	DGreyblue → GreyBlue
   153  //	DGreygreen → GreyGreen
   154  //	DMagenta → Magenta
   155  //	DMedGreen → MedGreen
   156  //	DMedblue → MedBlue
   157  //	DNofill → NoFill
   158  //	DNotacolor → undefined
   159  //	DOpaque → Opaque
   160  //	DPaleYellow → PaleYellow
   161  //	DPaleblue → PaleBlue
   162  //	DPalebluegreen → PaleBlueGreen
   163  //	DPalegreen → PaleGreen
   164  //	DPalegreyblue → PaleGreyBlue
   165  //	DPalegreygreen → PaleGreyGreen
   166  //	DPurpleblue → PurpleBlue
   167  //	DRed → Red
   168  //	DSUBF → unexported
   169  //	DTransparent → Transparent
   170  //	DWhite → White
   171  //	DYellow → Yellow
   172  //	DYellowgreen → YellowGreen
   173  //	Displaybufsize → unexported
   174  //	Drawop → Op
   175  //	Dx → Rectangle.Dx
   176  //	Dy → Rectangle.Dy
   177  //	Endarrow → EndArrow
   178  //	Enddisc → EndDisc
   179  //	Endmask → EndMask
   180  //	Endsquare → EndSquare
   181  //	Font → Font
   182  //	Fontchar → Fontchar
   183  //	Image → Image
   184  //	LOG2NFCACHE → unexported
   185  //	MAXFCACHE → unexported
   186  //	MAXSUBF → unexported
   187  //	NBITS, TYPE → Pix.Split
   188  //	NFCACHE → unexported
   189  //	NFLOOK → unexported
   190  //	NFSUBF → unexported
   191  //	NOREFRESH → not available
   192  //	Pfmt → not implemented; use %v instead of %P
   193  //	Point → Point (alias for image.Point)
   194  //	Rectangle → Rectangle (alias for image.Rectangle)
   195  //	Refbackup → RefBackup
   196  //	Refmesg → RefMesg
   197  //	Refnone → RefNone
   198  //	Rfmt → not implemented; use %v instead of %P
   199  //	SUBFAGE → unexported
   200  //	_allocwindow → unexported
   201  //	_screen → Display.Screen
   202  //	_string → unexported; use String, Runes, etc.
   203  //	addpt → Point.Add
   204  //	agefont → unexported
   205  //	allocimage → Display.AllocImage
   206  //	allocimagemix → Display.AllocImageMix
   207  //	allocscreen → Image.AllocScreen
   208  //	allocsubfont → unexported
   209  //	allocwindow → unexported
   210  //	arc → Image.Arc
   211  //	arcop → Image.ArcOp
   212  //	bezier → Image.Bezier
   213  //	bezierop → Image.BezierOp
   214  //	bezspline → Image.BSpline
   215  //	bezsplineop → Image.BSplineOp
   216  //	bezsplinepts → unexported
   217  //	border → Image.Border
   218  //	borderop → Image.BorderOp
   219  //	bottomnwindows → unexported
   220  //	bottomwindow → unexported
   221  //	bufimage → unexported
   222  //	buildfont → Display.BuildFont
   223  //	bytesperline → BytesPerLine
   224  //	cachechars → unexported
   225  //	canonrect → Rectangle.Canon
   226  //	chantodepth → Pix.Depth
   227  //	chantostr → Pix.String
   228  //	cloadimage → Image.Cload
   229  //	closedisplay → Display.Close
   230  //	cmap2rgb → unexported
   231  //	cmap2rgba → unexported
   232  //	combinerect → CombineRect
   233  //	creadimage → not available; use Display.ReadImage (readimage) with "compressed\n" prefix
   234  //	cursorset → Display.MoveCursor
   235  //	cursorswitch → Display.SwitchCursor
   236  //	display → global variable removed; use result of Init
   237  //	divpt → Point.Div
   238  //	draw → Image.Draw
   239  //	drawerror → not available
   240  //	drawlsetrefresh → not available
   241  //	drawop → Image.DrawOp
   242  //	drawrepl → Repl
   243  //	drawreplxy → ReplXY
   244  //	drawresizewindow → Display.Resize
   245  //	drawsetlabel → Display.SetLabel
   246  //	drawtopwindow → Display.Top
   247  //	ellipse → Image.Ellipse
   248  //	ellipseop → Image.EllipseOp
   249  //	eqpt → Point.Eq (or ==)
   250  //	eqrect → Rectangle.Eq (but treats all empty rectangles equal)
   251  //	fillarc → Image.FillArc
   252  //	fillarcop → Image.FillArcOp
   253  //	fillbezier, fillbezierop → not implemented
   254  //	fillbezspline, fillbezsplineop → not implemented
   255  //	fillellipse → Image.FillEllipse
   256  //	fillellipseop → Image.FillEllipseOp
   257  //	fillpoly → Image.FillPoly
   258  //	fillpolyop → Image.FillPolyOp
   259  //	flushimage → Display.Flush
   260  //	font → Display.Font
   261  //	freefont → Font.Free
   262  //	freeimage → Image.Free
   263  //	freescreen → Screen.Free
   264  //	freesubfont → unexported
   265  //	gendraw → Image.GenDraw
   266  //	gendrawop → Image.GenDrawOp
   267  //	gengetwindow → not available; use Display.Attach (getwindow)
   268  //	geninitdraw → not available; use Init (initdraw)
   269  //	getwindow → Display.Attach
   270  //	icossin → IntCosSin
   271  //	icossin2 → IntCosSin2
   272  //	initdraw → Init
   273  //	insetrect → Rectangle.Inset
   274  //	installsubfont → unexported
   275  //	line → Image.Line
   276  //	lineop → Image.LineOp
   277  //	loadchar → unexported
   278  //	loadhidpi → unexported
   279  //	loadimage → Image.Load
   280  //	lockdisplay → unexported
   281  //	lookupsubfont → unexported
   282  //	mkfont → unexported
   283  //	mulpt → Point.Mul
   284  //	namedimage → not available
   285  //	nameimage → not available
   286  //	newwindow → not available
   287  //	openfont → Display.OpenFont
   288  //	originwindow → unexported
   289  //	parsefontscale → unexported
   290  //	poly → Image.Poly
   291  //	polyop → Image.PolyOp
   292  //	ptinrect → Point.In
   293  //	publicscreen → unexported
   294  //	readimage → Display.ReadImage
   295  //	readsubfont → unexported
   296  //	readsubfonti → unexported
   297  //	rectXrect → RectXRect
   298  //	rectaddpt → Rectangle.Add
   299  //	rectclip → RectClip
   300  //	rectinrect → RectInRect
   301  //	rectsubpt → Rectangle.Sub
   302  //	replclipr → Image.ReplClipr
   303  //	rgb2cmap → unexported
   304  //	runestring, runestringn → Image.Runes
   305  //	runestringbg, runestringnbg → Image.RunesBg
   306  //	runestringbgop, runestringnbgop → Image.RunesBgOp
   307  //	runestringop, runestringnop → Image.RunesOp
   308  //	runestringsize → Font.RunesSize
   309  //	runestringwidth, runestringnwidth → Font.RunesWidth
   310  //	scalecursor → ScaleCursor
   311  //	scalesize → Display.Scale
   312  //	screen → Display.ScreenImage
   313  //	setalpha → Color.WithAlpha
   314  //	string, stringn → Image.String
   315  //	stringbg, stringnbg → Image.StringBg
   316  //	stringbgop, stringnbgop → Image.StringBgOp
   317  //	stringop, stringnop → Image.StringOp
   318  //	stringsize → Font.StringSize
   319  //	stringsubfont → not implemented
   320  //	stringwidth, stringnwidth → Font.StringWidth
   321  //	strsubfontwidth → not available
   322  //	strtochan → ParsePix
   323  //	subfontname → unexported
   324  //	subpt → Point.Sub
   325  //	swapfont → unexported
   326  //	topnwindows → unexported
   327  //	topwindow → unexported
   328  //	uint32 as color type → Color
   329  //	uint32 as image channel (format) type → Pix
   330  //	uninstallsubfont → unexported
   331  //	unloadimage → Image.Unload
   332  //	unlockdisplay → unexported
   333  //	wordsperline → WordsPerLine
   334  //	writeimage → not implemented (TODO)
   335  //	writesubfont → not available
   336  //
   337  // Note that the %P and %R print formats are now simply %v,
   338  // but since Point and Rectangle are aliases for the types in package image,
   339  // the formats have changed: Points and Rectangles format as
   340  // (1,2) and (1,2)-(3,4) instead of [1 2] and [[1 2] [3 4]].
   341  //
   342  package draw