status_t FFont::Unflatten(type_code c, const void *buf, ssize_t size) { if( c != FONT_TYPE ) return B_BAD_TYPE; // Make sure buffer contains all data. If we later want // to add new attributes, we can make a more sophisticated // check to allow partial structures. if( size < sizeof(flat_font_data) ) return B_BAD_VALUE; // Easy reference to the buffer. flat_font_data* fdat = (flat_font_data*)buf; // Initialize from default font, just in case. *this = FFont(); // Set up family and style for font. SetFamilyAndStyle(fdat->family,fdat->style); // This is used as a temporary when byte-swapping floats. // Note that this assumes a float is 4 bytes. union { uint32 aslong; float asfloat; } swap; // Byte-swap size, shear, and rotation out of the flattened // structure. This is written for clarity more than speed, // since the additional overhead will be entirely subsumed // by everything else going on. swap.asfloat = fdat->size; swap.aslong = ntohl(swap.aslong); SetSize(swap.asfloat); swap.asfloat = fdat->shear; swap.aslong = ntohl(swap.aslong); SetShear(swap.asfloat); swap.asfloat = fdat->rotation; swap.aslong = ntohl(swap.aslong); SetRotation(swap.asfloat); // Byte-swap the remaining data from the flattened structure. SetFlags(ntohl(fdat->flags)); SetFace(ntohs(fdat->face)); SetSpacing(fdat->spacing); SetEncoding(fdat->encoding); SetMask(ntohl(fdat->mask)); return B_NO_ERROR; }
void View3DAttributes::SetFromNode(DataNode *parentNode) { if(parentNode == 0) return; DataNode *searchNode = parentNode->GetNode("View3DAttributes"); if(searchNode == 0) return; DataNode *node; if((node = searchNode->GetNode("viewNormal")) != 0) SetViewNormal(node->AsDoubleArray()); if((node = searchNode->GetNode("focus")) != 0) SetFocus(node->AsDoubleArray()); if((node = searchNode->GetNode("viewUp")) != 0) SetViewUp(node->AsDoubleArray()); if((node = searchNode->GetNode("viewAngle")) != 0) SetViewAngle(node->AsDouble()); if((node = searchNode->GetNode("parallelScale")) != 0) SetParallelScale(node->AsDouble()); if((node = searchNode->GetNode("nearPlane")) != 0) SetNearPlane(node->AsDouble()); if((node = searchNode->GetNode("farPlane")) != 0) SetFarPlane(node->AsDouble()); if((node = searchNode->GetNode("imagePan")) != 0) SetImagePan(node->AsDoubleArray()); if((node = searchNode->GetNode("imageZoom")) != 0) SetImageZoom(node->AsDouble()); if((node = searchNode->GetNode("perspective")) != 0) SetPerspective(node->AsBool()); if((node = searchNode->GetNode("eyeAngle")) != 0) SetEyeAngle(node->AsDouble()); if((node = searchNode->GetNode("centerOfRotationSet")) != 0) SetCenterOfRotationSet(node->AsBool()); if((node = searchNode->GetNode("centerOfRotation")) != 0) SetCenterOfRotation(node->AsDoubleArray()); if((node = searchNode->GetNode("axis3DScaleFlag")) != 0) SetAxis3DScaleFlag(node->AsBool()); if((node = searchNode->GetNode("axis3DScales")) != 0) SetAxis3DScales(node->AsDoubleArray()); if((node = searchNode->GetNode("shear")) != 0) SetShear(node->AsDoubleArray()); if((node = searchNode->GetNode("windowValid")) != 0) SetWindowValid(node->AsBool()); }