Add COW textattrs. Clean up lo_SetColor. Make <TD>.bgcolor mutable.

Remove some debugging cruft.
This commit is contained in:
shaver%netscape.com 1998-09-05 04:29:56 +00:00
parent 06afe8d5f0
commit 2f8cc3501d
4 changed files with 78 additions and 69 deletions

View File

@ -934,6 +934,7 @@ extern int32 lo_baseline_adjust(MWContext *context, lo_DocState *state, LO_Eleme
extern void lo_UpdateElementPosition ( lo_DocState * state, LO_Element * element );
extern void lo_CopyTextAttr(LO_TextAttr *, LO_TextAttr *);
extern LO_TextAttr *lo_FetchTextAttr(lo_DocState *, LO_TextAttr *);
extern LO_TextAttr *lo_NewCopyTextAttr(lo_DocState *, LO_TextAttr *);
extern void lo_FindLineMargins(MWContext *, lo_DocState *, Bool updateFE);
extern void lo_AddMarginStack(lo_DocState *, int32, int32, int32, int32,
int32, int32, int32, intn);
@ -1186,7 +1187,8 @@ extern Bool lo_SetNamedAnchor(lo_DocState *, PA_Block);
#ifdef DOM
extern Bool lo_SetNamedSpan(lo_DocState *, PA_Block);
extern void lo_SetColor( LO_Element *ele, LO_Color *color, Bool background);
extern void lo_SetColor( LO_Element *ele, LO_Color *color, lo_DocState *state,
Bool background);
#endif
extern void lo_AddNameList(lo_DocState *, lo_DocState *);

View File

@ -30,7 +30,8 @@
/* Initial attempt at DOM by letting JS set style of SPAN contents */
void lo_SetColor( LO_Element *ele, LO_Color *color, Bool background);
void lo_SetColor( LO_Element *ele, LO_Color *color, lo_DocState *state,
Bool background);
static void lo_SetFontFamily( MWContext *context, LO_Element *ele, char *family);
static void lo_SetFontWeight( MWContext *context, LO_Element *ele, char *weight);
static void lo_SetFontSlant( MWContext *context, LO_Element *ele, char *weight);
@ -69,7 +70,9 @@ void LO_SetSpanColor(MWContext* context, void *span, LO_Color *color)
ele = parent_span->lo_any.next;
while (ele != NULL && ele->lo_any.type != LO_SPAN)
{
#if 0
lo_SetColor(ele, color, FALSE);
#endif
ele = ele->lo_any.next;
}
}
@ -84,7 +87,9 @@ void LO_SetSpanBackground(MWContext* context, void *span, LO_Color *color)
ele = parent_span->lo_any.next;
while (ele != NULL && ele->lo_any.type != LO_SPAN)
{
#if 0
lo_SetColor(ele, color, TRUE);
#endif
ele = ele->lo_any.next;
}
}
@ -167,45 +172,45 @@ lo_FindParentSpan( LO_Element *ele )
return (LO_SpanStruct *) ele;
}
void lo_SetColor( LO_Element *ele, LO_Color *color, Bool background)
#define GET_UNSHARED_TEXT_ATTR(new, old) \
PR_BEGIN_MACRO \
if ((old)->refcnt != 1) { \
(new) = lo_NewCopyTextAttr(state, (old)); \
(old)->refcnt--; \
} else { \
(new) = (old); \
} \
PR_END_MACRO
void lo_SetColor( LO_Element *ele, LO_Color *color, lo_DocState *state,
Bool background)
{
LO_TextAttr *new_attr;
switch (ele->lo_any.type)
{
case LO_TEXTBLOCK:
if (background)
{
ele->lo_textBlock.text_attr->bg = *color;
ele->lo_textBlock.text_attr->no_background = FALSE;
}
else
{
ele->lo_textBlock.text_attr->fg = *color;
}
GET_UNSHARED_TEXT_ATTR(new_attr, ele->lo_textBlock.text_attr);
ele->lo_textBlock.text_attr = new_attr;
break;
case LO_TEXT:
if (background)
{
ele->lo_text.text_attr->bg = *color;
ele->lo_text.text_attr->no_background = FALSE;
}
else
{
ele->lo_text.text_attr->fg = *color;
}
GET_UNSHARED_TEXT_ATTR(new_attr, ele->lo_text.text_attr);
ele->lo_text.text_attr = new_attr;
break;
case LO_BULLET:
if (background)
{
ele->lo_bullet.text_attr->bg = *color;
ele->lo_bullet.text_attr->no_background = FALSE;
}
else
{
ele->lo_bullet.text_attr->fg = *color;
}
GET_UNSHARED_TEXT_ATTR(new_attr, ele->lo_bullet.text_attr);
ele->lo_bullet.text_attr = new_attr;
break;
default:
break;
return;
}
if (background)
{
new_attr->bg = *color;
new_attr->no_background = FALSE;
}
else
{
new_attr->fg = *color;
}
}
@ -216,7 +221,6 @@ lo_SetFontFamily( MWContext *context,
char *new_face)
{
LO_TextAttr *text_attr;
LO_TextInfo text_info;
/* if the point size is different, tell the FE to release it's data,
set the point_size to the new value, and then have the FE
@ -265,7 +269,6 @@ lo_SetFontWeight( MWContext *context,
char *weight)
{
LO_TextAttr *text_attr;
LO_TextInfo text_info;
int new_weight = atoi(weight);
/* if the point size is different, tell the FE to release it's data,
@ -318,7 +321,6 @@ lo_SetFontSlant( MWContext *context,
char *slant)
{
LO_TextAttr *text_attr;
LO_TextInfo text_info;
int flag;
/* if the point size is different, tell the FE to release it's data,
@ -368,7 +370,6 @@ lo_SetFontSize( MWContext *context,
int32 new_size)
{
LO_TextAttr *text_attr;
LO_TextInfo text_info;
/* if the point size is different, tell the FE to release it's data,
set the point_size to the new value, and then have the FE

View File

@ -146,6 +146,12 @@ void LO_SetTableCellAttributes(MWContext *context, void *cell_v,
{
lo_TableCell *cell = (lo_TableCell *)cell_v;
LO_Element *start = cell->cell->cell_list, *end = cell->cell->cell_list_end;
lo_DocState *state;
lo_TopState *top = lo_FetchTopState(context->doc_id);
if (!top)
return;
state = top->doc_state;
if (!start)
return;
@ -163,7 +169,7 @@ void LO_SetTableCellAttributes(MWContext *context, void *cell_v,
fprintf(stderr, "setting bgcolor of %s to %s\n",
element_names[iter->type], value);
#endif
lo_SetColor(start, &rgb, TRUE);
lo_SetColor(start, &rgb, state, TRUE);
/* iter = iter->lo_any.next;
}
if (iter != start) {
@ -171,7 +177,7 @@ void LO_SetTableCellAttributes(MWContext *context, void *cell_v,
fprintf(stderr, "setting bgcolor of %s to %s\n",
element_names[iter->type], value);
#endif
lo_SetColor(start, &rgb, TRUE);
lo_SetColor(start, &rgb, state, TRUE);
}
*/
}

View File

@ -1253,6 +1253,35 @@ lo_CopyTextAttr(LO_TextAttr *old_attr, LO_TextAttr *new_attr)
new_attr->font_weight = old_attr->font_weight;
}
LO_TextAttr *
lo_NewCopyTextAttr(lo_DocState *state, LO_TextAttr *old_attr)
{
LO_TextAttr *new_attr;
LO_TextAttr **text_attr_hash;
int32 hash_index;
#ifdef DEBUG_shaver
fprintf(stderr, "allocing new TextAttr\n");
#endif
hash_index = (old_attr->fontmask & old_attr->attrmask) % FONT_HASH_SIZE;
XP_LOCK_BLOCK(text_attr_hash, LO_TextAttr **,
state->top_state->text_attr_hash);
new_attr = XP_NEW_ZAP(LO_TextAttr);
if (new_attr != NULL)
{
lo_CopyTextAttr(old_attr, new_attr);
new_attr->next = text_attr_hash[hash_index];
text_attr_hash[hash_index] = new_attr;
new_attr->refcnt = 1;
}
else
{
state->top_state->out_of_memory = TRUE;
}
XP_UNLOCK_BLOCK(state->top_state->text_attr_hash);
return new_attr;
}
LO_TextAttr *
lo_FetchTextAttr(lo_DocState *state, LO_TextAttr *old_attr)
@ -1292,25 +1321,15 @@ lo_FetchTextAttr(lo_DocState *state, LO_TextAttr *old_attr)
#endif
)
{
break;
attr_ptr->refcnt++;
break;
}
attr_ptr = attr_ptr->next;
}
if (attr_ptr == NULL)
{
LO_TextAttr *new_attr;
new_attr = XP_NEW_ZAP(LO_TextAttr);
if (new_attr != NULL)
{
lo_CopyTextAttr(old_attr, new_attr);
new_attr->next = text_attr_hash[hash_index];
text_attr_hash[hash_index] = new_attr;
}
else
{
state->top_state->out_of_memory = TRUE;
}
new_attr = lo_NewCopyTextAttr(state, old_attr);
attr_ptr = new_attr;
}
@ -2580,7 +2599,6 @@ lo_SetNodeElement(lo_DocState *state, LO_Element *element)
DOM_Node *node = CURRENT_NODE(state);
#ifdef DEBUG_shaver_0
fprintf(stderr, "lo_SetNodeElement: state %x: ", state);
if (!node)
fprintf(stderr, "NULL node\n");
else if (node->type == NODE_TYPE_DOCUMENT)
@ -2592,24 +2610,6 @@ lo_SetNodeElement(lo_DocState *state, LO_Element *element)
if (!eptr) {
/* this the first element for this node, so mark it */
ELEMENT_PRIV(node)->ele_start = element;
#ifdef DEBUG_shaver
fprintf(stderr, "giving node %s element %s\n",
ELEMENT_PRIV(node)->tagtype ?
PA_TagString(ELEMENT_PRIV(node)->tagtype) : "TEXT",
element->type > 0 &&
element->type <= 31 ? element_names[element->type]
: "UNKNOWN", state);
#endif
} else {
#ifdef DEBUG_shaver
fprintf(stderr, "node %s %s already has element %s\n",
ELEMENT_PRIV(node)->tagtype ?
PA_TagString(ELEMENT_PRIV(node)->tagtype) : "TEXT",
node->name ? node->name : "NULL",
element->type > 0 &&
element->type <= 31 ? element_names[element->type]
: "UNKNOWN");
#endif
}
}
}