Anti-nuisance lawsuit warning: The purpose of these notes is to remind me, Zoegond, of stuff or to help me work stuff out. They may contain mistakes.

Quick

  • ($a, $b....) = unpack("A2A7...", $packed)
  • push( array, list )

Tuesday, March 30, 2010

Array declaration and initialisation

byte[] inbf = new byte[1024];

(Remember C# rarely lets you declare a variable without initialising it)

Monday, March 22, 2010

Path closing and filling

The area enclosed by an SVG path is filled in if the /fill/ attribute is anything other than "none".

Whether the path is closed or not (with z) does not affect filling, it only affects the strokes.

Thursday, March 11, 2010

SVG text

Experiments show that a line of SVG text has four strata or horizontal layers of equal height:

TOP QUARTER only used by descenders from the line above

UPPER CAPITAL QUARTER only used by upper parts of capitals, and ascenders

UPPER MINISCULE QUARTER midparts of capitals, and upper part of x-height

LOWER QUARTER lowest part of x-height

-------------

DESCENDER QUARTER (overlaps TOP QUARTER of line below
)


That's to say, if you specify your text to have font-size 6 then the space occupied by the four quarters will be 6 units, with each quarter taking up 1.5 units. Similarly you should use 6 as the dy when placing tspans to do multiple lines of text.

(It seems that while Arial follows this pattern, other fonts may not, any unfamiliar font should be experimentally displayed first for measurement).

Wednesday, March 10, 2010

StringBuilder

The way to replace the contents of a StringBuilder seems to be

sb.Length = 0;
sb.Append("New stuff");

string comparison

s1 == s2

is the same as saying

s1.Equals(s2)

and neither of them is a C++ 'is it exactly the same object' trap.

There is also Compare but I'm not clear as to the difference.

string concatenation

Concatenate strings with + . If you're doing this in a loop, you should be using a StringBuilder not a String (StringBuilder.append).

However, an expression like

s1 + s2 + s3 + s4

is apparently optimised by the compiler so that it is not done as three separate string copies.

Tuesday, March 9, 2010

exists

If you do a check like

if (exists($h->{a}{b}{c})) ...

$h->{a}{b}{c} won't be created as part of the check, but $h->{a} and $h->{a}{b} will. Beware!

Property calls on command results

To get a property of the object returned by a command, do thusly

(get-date).tofiletime()

NB that

(get-date).tofiletime

will get you the 'tofiletime' member itself, a bit like a function pointer in C and probably not what you want.

where-object

where-object takes a bit of code as a parameter. Context seems to be that $_ is the object. Alpha comparison operators are used.

gci | where-object { $_.length -lt 500 }

select-object

Despite its name select-object determines which properties ('columns') of the object are to be displayed.

gci | select-object length

Thursday, March 4, 2010

Perl filehandle manoeuvre

sub_me(*FH);

#

sub sub_me
{
local (*FHANDLE) = @_;

while (<FHANDLE>)
{
}
}

Tuesday, March 2, 2010

SVG text

If you place text at x,y then that's where the bottom left-hand corner of the body-part of the text will go. The main part of the letters extends upwards from x,y.

Don't let this make you forget that in SVG the grid runs the other way, ie the positive y-direction is downwards.

Monday, March 1, 2010

Perl for loops

for($n = 0; $n<10; ++$n) {
}
print $n;

will print 10, not 9. $n is incremented the last time control returns to the for - ++$n happens before the $n<10 check, because the loop control statement means

1. If this is the first iteration, $n = 0
2. if $n < 10, execute the loop body...
3. .. then ++$n
4. goto 1

Followers

Blog Archive