Theory of the Structure of Ferromagnetic Domains in Films and Small Particles